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

 

#define int long long

//#pragma GCC optimize("Ofast")

//#pragma GCC optimize("unroll-loops")

//#pragma comment(linker, "/stack:200000000")

//#pragma GCC optimize("Ofast,no-stack-protector") 

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

 

 

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

#define forev(i, b, a) for(int i = (b); i >= (a); --i)

#define forn(i, a, b) for(int i = (a); i <= (b); ++i)

#define all(x) x.begin(), x.end()

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

#define pb push_back

#define ppb pop_back

#define mp make_pair

#define s second

#define f first

 

 

using namespace std;

 

 

typedef pair < long long, long long > pll;    

typedef pair < int, int > pii;

typedef unsigned long long ull;         

typedef vector < pii > vpii;

typedef vector < int > vi;

typedef long double ldb; 

typedef long long ll;  

typedef double db;                         

 

 

const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;

const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);

const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;

const db eps = 1e-12, pi = 3.14159265359;

const ll INF = 1e18;





int n, m, l, r, x, t[N << 2], add[N << 2], dp[N];

vpii gg[N];

vi g[N];





void push (int v) {

	if (add[v]) {

		add[v << 1] += add[v];

		add[v << 1 | 1] += add[v];

		t[v << 1] += add[v];

		t[v << 1 | 1] += add[v];

		add[v] = 0;

	}

}





void update (int l, int r, int x, int v = 1, int tl = 0, int tr = n) {

	if (l > r || l > tr || tl > r) 

		return;

	

	if (l <= tl && tr <= r) {

		t[v] += x;

		add[v] += x;

		return;

	}



	push(v);

	int tm = (tl + tr) >> 1;

	update(l, r, x, v << 1, tl, tm);

	update(l, r, x, v << 1 | 1, tm + 1, tr);

	t[v] = max(t[v << 1], t[v << 1 | 1]);

}



int get (int l, int r, int v = 1, int tl = 0, int tr = n) {

	if (l > r || tl > r || l > tr)

		return -INF;



	if (l <= tl && tr <= r) 

		return t[v]; 

	



	push(v);

	int tm = (tl + tr) >> 1;

	return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));

}







main () {

	cin >> n >> m;

	while (m--) {

		cin >> l >> r >> x;

		g[l].pb(x);		

		gg[r + 1].pb({l, x});

	}





	forn (i, 1, n) {

		for (auto x : g[i]) 

			update(0, i - 1, x); 



		for (auto x : gg[i]) 

			update(0, x.f - 1, -x.s); 



		dp[i] = get(0, i - 1);			

		update(i, i, dp[i]);					

	}	

	



	cout << *max_element(dp, dp + 1 + n);	

}          

 

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#include <cstring>

#include <iostream>



using namespace std;



typedef long long ll; 

const int MAXN = 200010;

const ll  INF = 1e16+1;



int n, m;

struct iv{

	int l, r, w;

	bool operator<(const iv &o)const{return r!=o.r?r<o.r:l<o.l;}

}a[MAXN];



ll f[MAXN];



struct node{

	int l, r;

	ll maxx, tag;

}t[MAXN<<2];

inline void pushUp(int k){

	t[k].maxx = max(t[k<<1].maxx, t[k<<1|1].maxx);

}

inline void pushDown(int k)

{

	if(!t[k].tag) return ;

	t[k<<1].maxx   += t[k].tag;

	t[k<<1|1].maxx += t[k].tag;

	t[k<<1].tag    += t[k].tag;

	t[k<<1|1].tag  += t[k].tag;

	t[k].tag = 0;

}

void build(int l, int r, int k)

{

	t[k].l = l; t[k].r = r; t[k].maxx = 0; t[k].tag = 0;

	if(l == r) return ;

	int mid = l + r >> 1;

	build(l, mid, k<<1);

	build(mid+1, r, k<<1|1);

	pushUp(k);

}

void update(int x, int y, ll val, int k)

{

	if(t[k].l >= x && t[k].r <= y){

		t[k].maxx += val;

		t[k].tag += val;

		return ;

	}

	pushDown(k);

	int mid = t[k].l + t[k].r >> 1;

	if(x <= mid) update(x, y, val, k<<1);

	if(y >= mid+1) update(x, y, val, k<<1|1);

	pushUp(k);

}

ll query(int x, int y, int k)

{

	if(t[k].l >= x && t[k].r <= y) return t[k].maxx;

	pushDown(k);

	int mid = t[k].l + t[k].r >> 1;

	ll res = -INF;

	if(x <= mid) res = max(res, query(x, y, k<<1));

	if(y >= mid+1) res = max(res, query(x, y, k<<1|1));

	return res;

}



int main()

{

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

	for(int i=1;i<=m;i++)

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

	sort(a+1, a+m+1);

	a[m+1].r = 0;

	build(1, n, 1);

	int now = 1;

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

	{

		update(i, i, query(1, i, 1), 1);

		while(a[now].r == i){

			update(a[now].l, a[now].r, a[now].w, 1);

			++now;

		}

	}

	printf("%lld\n",max(query(1, n, 1), 0ll));

	return 0;

}

// Fastest known solution for this problem: