// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ull unsigned long long

#define ll long long

#define endl '\n'

#define pb push_back

#define mod 1000000007

#define mp make_pair

#define pi acos(-1)

#define line cout<<"----------------------------"<<endl

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)

#define filein freopen("input.text","r",stdin)

#define fileout freopen("output.txt","w",stdout)

using namespace std;

const ll mx=200009;	

ll tree[mx*4]; 

ll lazy[mx*4]; 

vector<pair<ll,ll> >l[mx],r[mx]; 

void pushdown(ll node,ll b, ll e)

{

	if(lazy[node])

	{

		tree[node]+=lazy[node]; 

		if(b!=e)

		{

			lazy[node*2]+=lazy[node]; 

			lazy[node*2+1]+=lazy[node]; 

		}

		lazy[node]=0; 

	}

}

void update(ll node, ll b, ll e, ll i, ll j, ll val )

{

	pushdown(node,b,e);

	if(b>j or e<i) return ; 

	if(b>=i and e<=j)

	{

		lazy[node]+=val; 

		pushdown(node,b,e);

		return ;

	}

	ll mid=(b+e)>>1;

	update(node*2,b,mid,i,j,val);

	update(node*2+1,mid+1,e,i,j,val);

	tree[node]=max(tree[node*2],tree[node*2+1]);

}

ll query(ll node, ll b,ll e, ll i, ll j)

{

	pushdown(node,b,e);

	if(b>j or e<i) return LLONG_MIN; 

	if(b>=i and e<=j) return tree[node]; 

	ll mid=(b+e)>>1; 

	return max(query(node*2,b,mid,i,j),query(node*2+1,mid+1,e,i,j));

}

int main()

{

	ll n,m; 

	cin>>n>>m; 

	for(ll i=0;i<m;i++)

	{

		ll a,b,c; 

		cin>>a>>b>>c;

		l[a].pb(mp(a,c));

		r[b].pb(mp(a,c));

	}

	ll ans=0; 

	for(ll i=1;i<=n;i++)

	{

		for(auto x: l[i])

		{

			update(1,0,n,0,x.first-1,x.second);; 

		}

		ll curval=query(1,0,n,0,i-1);

		ans=max(ans,curval);

		update(1,0,n,i,i,curval);

		for(auto x: r[i])

		{

			update(1,0,n,0,x.first-1,-x.second);

		}

	}

	cout<<ans<<endl; 

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

#define for0(i, n) for(int i = 0; i < n; ++i)

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 2e5+10;

const int M = 1e6+10;

/*=================================================================================*/



int n, m;

ll sum[N<<2], tag[N<<2];

struct node {

   int l, r, a;

}b[N];



bool cmp(node x, node y) {

   return x.r < y.r;

}



void add(int rt, int L, int R, int x, int y, ll val) {

   if(x <= L && y >= R) {

      sum[rt] += val, tag[rt] += val;

      return;

   }

   int mid = (L + R) >> 1;

   if(x <= mid) add(rt<<1, L, mid, x, y, val);

   if(y > mid) add(rt << 1 | 1, mid+1, R, x, y, val);

   sum[rt] = max(sum[rt<<1], sum[rt<<1|1]) + tag[rt];

}



int main() {

   scanf("%d %d", &n, &m);

   for1(i, m) {

      scanf("%d %d %d", &b[i].l, &b[i].r, &b[i].a);   

   }

   sort(b+1, b+1+m, cmp);

   int idx = 1;

   for1(i, n) {

      add(1, 1, n, i, i, sum[1]);

      while(b[idx].r == i) {

         // debug1 printf("%d %d %d\n", b[idx].l, b[idx].r, b[i].a);

         add(1, 1, n, b[idx].l, i, b[idx].a);

         idx++;

      }

   }

   cout << max(sum[1], (ll)0) << endl;

   return 0;

}

// Fastest known solution for this problem: