#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 30000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct Node{
int st,ed;
int num;
bool operator < (const Node &rhs)const{
return ed<rhs.ed;
}
}a[N];
bool vis[N];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d%d%d",&a[i].st,&a[i].ed,&a[i].num);
sort(a+1,a+1+m);
int res=0;
for(int i=1;i<=m;i++){
int used=0;
for(int j=a[i].st;j<=a[i].ed;j++)//从前向后统计已有多少树
if(vis[j])
used++;
if(used<a[i].num){//若树的个数不到当前区间所需个数
for(int j=a[i].ed;j>=a[i].st;j--){//从后向前在当前区间种树
if(!vis[j]){
vis[j]=true;
used++;
res++;
if(used==a[i].num)
break;
}
}
}
}
printf("%d\n",res);
return 0;
}