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

}          

 

// Faster C++ solution for the same problem (measured speedup: 1.8859910334865135x):
//#pragma GCC target ("avx2,sse2")

//#pragma GCC optimization ("Ofast")

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

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;



#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long

#define ull unsigned long long

#define db double

#define pb push_back

#define pf push_front

#define ppb pop_back

#define ppf pop_front

#define fi first

#define se second

#define mp make_pair

#define up_b upper_bound

#define low_b lower_bound

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

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

#define endl "\n"



#define left fsdsdfoisf

#define sum dpsdfioppsf

#define assign xcvjlkdjfio

#define trie fksdfkjkfnjuiv

#define next sidlfjsfkl

#define merge sdfksdkfsldf



#define int long long



using namespace std;



void dout() {

    cerr << endl;

}

template <typename Head, typename... Tail>

void dout(Head H, Tail... T) {

    cerr << H << ' ';

    dout(T...);

}



//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair <int, int> pii;



const int N = 2e5 + 7, inf = 1e18;

int n, m, dp[N], sum, t[N * 4], add[N * 4];

vector <pii> v[N];



void push(int v, int tl, int tr) {

    if (add[v]) {

        int tm = tl + tr >> 1;

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

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

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

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

        add[v] = 0;

    }

}



void build(int v, int tl, int tr) {

    if (tl == tr) {

        t[v] = -inf;

        return;

    }

    int tm = tl + tr >> 1;

    build(v << 1, tl, tm);

    build(v << 1 | 1, tm + 1, tr);

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

}



void update(int v, int tl, int tr, int l, int r, int x) {

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

        return;

    }

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

        t[v] += x;

        add[v] += x;

        return;

    }

    int tm = tl + tr >> 1;

    push(v, tl, tr);

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

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

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

}



int getmax(int v, int tl, int tr, int l, int r) {

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

        return -inf;

    }

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

        return t[v];

    }

    int tm = tl + tr >> 1;

    push(v, tl, tr);

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

}



void upd(int x, int y) {

    int val = getmax(1, 1, n, x, x);

    update(1, 1, n, x, x, y - val);

}



void solve(int tc) {

    // check for (int i = 0; i < n; j++)

    cin >> n >> m;

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

        int l, r, a;

        cin >> l >> r >> a;

        v[r].pb({l, a});

        sum += a;

    }

    dp[1] = sum;

    build(1, 1, n);

    upd(1, dp[1]);

    int cur = 0;

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

        for (auto j : v[i - 1]) {

            int l = j.fi, a = j.se;

            if (l > 1) {

                update(1, 1, n, 1, l - 1, -a);

            }

            cur += a;

        }

        dp[i] = getmax(1, 1, n, 1, i - 1);

        dp[i] = max(dp[i], sum - cur);

        if (i <= n) {

            upd(i, dp[i]);

        }

    }

    cout << dp[n + 1];

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    int tc = 1;

//    cin >> tc;

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

        solve(i);

//        cleanup();

    }

}