// 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.8844486883498144x):
// oh, the less I know the better

// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz

#include <bits/stdc++.h>

#define endl '\n'

#define fst first

#define snd second

#define pb push_back

#define sz(x) int(x.size())

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

#define trace(x) cout << #x << " = " << x << endl

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

typedef long long ll;

typedef pair<int,int> ii;

const int N = 2e5+20;

const ll INF = 1e18;



struct STree{ // example: range sum with range addition

	vector<ll> st,lazy;int n;

	STree(int n): st(4*n+5,0), lazy(4*n+5,0), n(n) {}

	void push(int k, int s, int e){

		if(!lazy[k])return; // if neutral, nothing to do

		st[k]+=lazy[k]; // update st according to lazy

		if(s+1<e){ // propagate to children

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

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

		}

		lazy[k]=0; // clear node lazy

	}

	void upd(int k, int s, int e, int a, int b, ll v){

		push(k,s,e);

		if(s>=b||e<=a)return;

		if(s>=a&&e<=b){

			lazy[k]+=v; // accumulate lazy

			push(k,s,e);return;

		}

		int m=(s+e)/2;

		upd(2*k,s,m,a,b,v);upd(2*k+1,m,e,a,b,v);

		st[k]=min(st[2*k],st[2*k+1]); // operation

	}

	ll query(int k, int s, int e, int a, int b){

		if(s>=b||e<=a)return INF; // operation neutral

		push(k,s,e);

		if(s>=a&&e<=b)return st[k];

		int m=(s+e)/2;

		return min(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b)); // operation

	}

	void upd(int a, int b, ll v){upd(1,0,n,a,b,v);}

	ll query(int a, int b){return query(1,0,n,a,b);}

};  // usage: STree rmq(n);rmq.init(x);rmq.upd(s,e,v);rmq.query(s,e);



vector<ii> intv[N];



int main(){



	fastio;

	int n,m;

	cin >> n >> m;

	ll ans = 0;

	for(int i = 0; i < m; ++i){

		int l,r,a;

		cin >> l >> r >> a;

		ans += a;

		intv[r].pb(ii(l,a));

	}



	ll res = INF;

	STree st(n+5);

	for(int i = 1; i <= n+1; ++i){

		for(auto par : intv[i-1]){

			int l = par.fst, val = par.snd;

			st.upd(0,l,val);

		}

		st.upd(i,i+1,st.query(0,i));

	}

	res = st.query(0,n+1);

	cout << ans-res << endl;



	return 0;

}