#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h;
cin>>n>>h;
int b[h],e[h],t[h],tree[n]={0},ans=0;
for(int i=0;i<h;i++)cin>>b[i]>>e[i]>>t[i];
for(int i=0;i<h;i++)
for(int j=0;i<h;j++)
if(t[i]<t[j]){
swap(b[i],b[j]);
swap(e[i],e[j]);
swap(t[i],t[j]);
}
for(int i=0;i<h;i++)
for(int j=b[i]-1;j<e[i];j++)
if(tree[j]==0){
ans++;
tree[i]=1;
}
cout<<ans;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h;
cin>>n>>h;
int b[h],e[h],t[h],tree[n]={0},ans=0;
for(int i=0;i<h;i++)cin>>b[i]>>e[i]>>t[i];
for(int i=0;i<h;i++)
for(int j=0;i<h;j++)
if(t[i]<t[j]){
swap(b[i],b[j]);
swap(e[i],e[j]);
swap(t[i],t[j]);
}
for(int i=0;i<h;i++)
for(int j=b[i]-1;j<e[i];j++)
if(tree[j]==0){
ans++;
tree[i]=1;
}
cout<<ans;
return 0;
}