//2023/4/1
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1e6+10;
int num,ans;
struct house{
int b;
int e;
int t;
}a[50010];
bool vis[300100];
bool cmp(house x,house y)
{
return x.e<y.e;
}
signed main()
{
int n,m;
cin>>n>>m;
for (int i=1;i<=m;i++)
{
cin>>a[i].b>>a[i].e>>a[i].t;
}
sort(a+1,a+1+m,cmp);
for (int i=1;i<=n;i++)
{
for (int j=a[i].b;j<=a[i].e;j++)
{
if(vis[j]==1)
{
a[i].t--;
}
}
for (int j=a[i].e;j>=a[i].b;j--)
{
if(a[i].t<=0)
{
break;
}
if (vis[j]==0)
{
vis[j]=1;
a[i].t--;
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}