// Slower C++ solution:
#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; 

}




// Faster C++ solution for the same problem (measured speedup: 1.2435501055000961x):
#include<bits/stdc++.h>

typedef long long ll;

using namespace std;

vector<ll>dp(1<<19,-2e18);

vector<ll>buf(1<<19);

ll n,m,ans;

void up(ll v, ll l, ll r) {

    dp[v]+=buf[v];

    if (l<r-1)

	{

        buf[2*v+1]+=buf[v];

        buf[2*v+2]+=buf[v];

    }

    buf[v]=0;

}

void add(ll v,ll l,ll r,ll L,ll R,ll x)

{

    up(v,l,r);

    if(r<=L||R<=l)return;

    if(L<=l&&r<=R)

	{

        buf[v]+=x;

        up(v,l,r);

        return;

    }

    ll m=(l+r)/2;

    add(2*v+1,l,m,L,R,x);

    add(2*v+2,m,r,L,R,x);

    dp[v]=max(dp[2*v+1],dp[2*v+2]);

}

void se(ll v,ll l,ll r,ll i,ll x)

{

    up(v,l,r);

    if(l==r-1)

	{

        dp[v]=x;

        return;

    }

    ll m=(l+r)/2;

    if(i<m)

	{

        se(2*v+1,l,m,i,x);

        up(2*v+2,m,r);

    }

	else

	{

        up(2*v+1,l,m);

        se(2*v+2,m,r,i,x);

    }

    dp[v]=max(dp[2*v+1],dp[2*v+2]);

}

int main()

{

    cin>>n>>m;

    vector<ll>l(n,0);

    vector<vector<pair<ll,ll> > >vec(n + 1);

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

	{

        ll L,R,a;

        cin>>L>>R>>a;

        L--;

        l[L]+=a;

		vec[R].push_back(make_pair(L,a));

    }

    se(0,-1,n,-1,0);

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

	{

        add(0,-1,n,-1,i,l[i]);

        for(ll j=0;j<vec[i].size();j++)

		{

			pair<ll,ll>x=vec[i][j];

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

        }

        ans=max(ans,dp[0]);

        se(0,-1,n,i,dp[0]);

    }

    cout<<ans;

    return 0;

}