#include<bits/stdc++.h>
using namespace std;
struct U{
int begin,end,tree;
}sz[100005];
int m,n,ans;
bool cmp(U i,U j){
if (i.end<j.end) return 1;
return 0;
}
int main(){
cin>>m>>n;
for (int i=1;i<=n;i++) cin>>sz[i].begin>>sz[i].end>>sz[i].tree;
sort(sz+1,sz+n+1,cmp);
int k=1;
ans+=sz[1].tree;
for (int i=2;i<=n;i++){
int qj=sz[i-k].end-sz[i].begin+1;
if (qj>=sz[i].tree) {
k++;
continue;
}
else if (qj<=0) {
k=1;
ans+=sz[i].tree;
}
else if (qj>0&&qj<sz[i].tree) {
k=1;
ans+=sz[i].tree-qj;
}
}
cout<<ans<<endl;
return 0;
}