//感谢模板和wawawawa大神的指导
//代码含全角空格
#include <iostream>
#include <cstdio>
#include <cstring>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int N=10005;
const int inf=0x3f3f3f3f;
int sum[N<<2];
int lazy[N<<2];
void pushup(int rt){
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void pushdown(int rt,int m){
if(lazy[rt]!=-1){//是否标记
lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
sum[rt<<1]= (m-(m >> 1))*lazy[rt];//这样就不用判断奇偶
sum[rt<<1|1]=(m >> 1)*lazy[rt];
/*
sum[rt<<1]=m >> 1;
sum[rt<<1|1]=m >> 1;
if (m & 1)判断奇偶
++sum[rt << 1];
*/
lazy[rt]=-1;
}
}
void build(int l,int r,int rt){
lazy[rt]=-1;//初始,未标记
sum[rt]=0;
if(l==r)return ;
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt){
if(L<=l&&R>=r){//为区间长,包含在所查询的区间时就标记(operate);
lazy[rt]=c;//标记
sum[rt]=(r-l+1)*c;//此区间内颜色c的总数
return;
}
pushdown(rt,r-l+1);//后者区间长
int m=(l+r)>>1;
if(L <= m)update(L,R,c,lson);
if(R > m) update(L,R,c,rson);
pushup(rt);
}
int main()
{
int n,m,x,y,c;
while(scanf("%d%d",&n,&m)==2){
build(1,n,1);
while(m--){
scanf("%d%d%d",&x,&y,&c);
if(x>y){
int tmp=y;y=x;x=tmp;
}
update(x,y,c,1,n,1);
}
printf("%d\n",n-sum[1]);
}
return 0;
}