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

    }

}


// Faster C++ solution for the same problem (measured speedup: 6.561787584838999x):
#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;

}