using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    int N;
    int M;

    void calc()
    {
        cin = new Scanner();
        N = cin.nextInt();
        M = cin.nextInt();

        int N2 = N + 5;
        List<Tuple<int, int>>[] tp = new List<Tuple<int, int>>[N2];
        for (int i = 0; i < N2; i++)
        {
            tp[i] = new List<Tuple<int, int>>();
        }

        long AllSum = 0;
        for (int i = 0; i < M; i++)
        {
            int l = cin.nextInt();
            int r = cin.nextInt();
            int a = cin.nextInt();
            tp[r].Add(Tuple.Create(l, a));
            AllSum += a;
        }

        Segtree Seg = new Segtree(N2);

        long[] dp = new long[N2];
        for (int i = 1; i < N2; i++)
        {
            dp[i] = dp[i - 1];
            foreach (var t in tp[i - 1])
            {
                int l = t.Item1;
                int a = t.Item2;
                Seg.add(0, l, a);
            }
            dp[i] = Math.Min(dp[i], Seg.getMin(0, i));
            Seg.add(i, i + 1, dp[i]);
        }

        Console.WriteLine(AllSum - dp[N2 - 1]);
    }

    class Segtree
    {
        int N;
        int[] L;
        int[] R;
        int[] M;
        int[,] np;
        bool[] lazyFlag;

        public Segtree(int _N)
        {
            N = 1;
            while (N < _N) N *= 2;

            L = new int[N * 2];
            R = new int[N * 2];
            M = new int[N * 2];
            np = new int[N * 2, 2];
            lazyFlag = new bool[N * 2];
            L[0] = 0;
            R[0] = N;
            M[0] = N / 2;

            for (int i = 0; i < N - 1; i++)
            {
                np[i, 0] = i * 2 + 1;
                np[i, 1] = i * 2 + 2;
                L[np[i, 0]] = L[i];
                R[np[i, 0]] = L[np[i, 1]] = (L[i] + R[i]) / 2;
                R[np[i, 1]] = R[i];
            }
            for (int i = 0; i < N; i++)
            {
                M[i] = (L[i] + R[i]) / 2;
            }
            init();
        }

        long[] sum;
        long[] lazyadd;
        long[] Min;

        void init()
        {
            sum = new long[2 * N];
            lazyadd = new long[2 * N];
            Min = new long[2 * N];
        }

        //遅延評価する分を伝播させる
        void lazy(int p)
        {
            if (!lazyFlag[p]) return;
            lazyFlag[p] = false;

            add(L[p], M[p], lazyadd[p], np[p, 0]);
            add(M[p], R[p], lazyadd[p], np[p, 1]);

            lazyadd[p] = 0;
        }

        //親の更新処理
        public void merge(int p)
        {
            Min[p] = Math.Min(Min[np[p, 0]], Min[np[p, 1]]);
            sum[p] = sum[np[p, 0]] + sum[np[p, 1]];
        }

        public long getSum(int l, int r, int p = 0)
        {
            if (l == L[p] && r == R[p])
            {
                //一致時処理
                return sum[p];
            }
            else
            {
                //遅延評価分の伝播
                lazy(p);

                //子の集計
                long ans = 0;
                if (l < M[p]) ans += getSum(l, Math.Min(M[p], r), np[p, 0]);
                if (r > M[p]) ans += getSum(Math.Max(l, M[p]), r, np[p, 1]);
                return ans;
            }
        }

        public long getMin(int l, int r, int p = 0)
        {
            if (l == L[p] && r == R[p])
            {
                //一致時処理
                return Min[p];
            }
            else
            {
                //遅延評価分の伝播
                lazy(p);

                //子の集計
                long ans = 0;
                if (l < M[p]) ans = Math.Min(ans, getMin(l, Math.Min(M[p], r), np[p, 0]));
                if (r > M[p]) ans = Math.Min(ans, getMin(Math.Max(l, M[p]), r, np[p, 1]));

                return ans;
            }
        }

        public void add(int l, int r, long v, int p = 0)
        {
            if (l == L[p] && r == R[p])
            {
                //一致時処理
                Min[p] += v;
                sum[p] += v * (r - l);
                lazyadd[p] += v;
                lazyFlag[p] = true;
            }
            else
            {
                //遅延評価分の伝播
                lazy(p);
                //子の更新
                if (l < M[p]) add(l, Math.Min(M[p], r), v, np[p, 0]);
                if (r > M[p]) add(Math.Max(l, M[p]), r, v, np[p, 1]);
                //親の更新
                merge(p);

            }
        }
    }


}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 65632