using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        //写経(https://ferin-tech.hatenablog.com/entry/2019/01/09/101410)
        static void Main(string[] args)
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var g = new int[N].Select(_ => new List<KeyValuePair<long, long>>()).ToArray();
            for(var i=0;i<M;++i)
            {
                var t = Sarray();
                g[t[1] - 1].Add(new KeyValuePair<long, long>(t[0] - 1, t[2]));
            }
            Func<long, long, long> f = (a, b) => Max(a, b);
            Func<long, long, long> h = (a, b) => a + b;
            LazySegmentTree<long, long> seg = new LazySegmentTree<long, long>((int)N + 2, f, h, h, 0, 0);

            for(var i=0;i<N;++i)
            {
                long now = 0;
                if (i != 0) now = Max(now, seg.query(0, i));
                seg.update(i, i + 1, now);
                foreach (var p in g[i])
                    seg.update((int)p.Key, i + 1, p.Value);
            }
            long ans = Max(0L, seg.query(0, (int)N + 1));
            WriteLine(ans);
        }
        public class LazySegmentTree<Monoid, OperatorMonoid> where OperatorMonoid : IEquatable<OperatorMonoid>
        {
            int sz, height;
            Monoid[] data;
            OperatorMonoid[] lazy;
            readonly Func<Monoid, Monoid, Monoid> f;
            readonly Func<Monoid, OperatorMonoid, Monoid> g;
            readonly Func<OperatorMonoid, OperatorMonoid, OperatorMonoid> h;
            readonly Monoid M1;
            readonly OperatorMonoid OM0;

            public LazySegmentTree(int n,
                Func<Monoid, Monoid, Monoid> f, Func<Monoid, OperatorMonoid, Monoid> g, Func<OperatorMonoid, OperatorMonoid, OperatorMonoid> h,
                Monoid M1, OperatorMonoid OM0
                )
            {
                this.f = f;
                this.g = g;
                this.h = h;
                this.M1 = M1;
                this.OM0 = OM0;
                sz = 1;
                height = 0;
                while (sz < n) { sz <<= 1; ++height; }
                data = new int[sz * 2].Select(_ => M1).ToArray();
                lazy = new int[sz * 2].Select(_ => OM0).ToArray();
            }
            public void set(int k, Monoid x) => data[k + sz] = x;
            public void build()
            {
                for (int k = sz - 1; 0 < k; --k)
                    data[k] = f(data[2 * k + 0], data[2 * k + 1]);
            }
            void propagete(int k)
            {
                if (!lazy[k].Equals(OM0))
                {
                    lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
                    lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
                    data[k] = reflect(k);
                    lazy[k] = OM0;
                }
            }
            Monoid reflect(int k) => lazy[k].Equals(OM0) ? data[k] : g(data[k], lazy[k]);
            void recalc(int k)
            {
                while (0 != (k >>= 1))
                {
                    data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
                }
            }
            void thrust(int k)
            {
                for (int i = height; 0 < i; --i)
                    propagete(k >> i);
            }
            public void update(int a, int b, OperatorMonoid x)
            {
                thrust(a += sz);
                thrust(b += sz - 1);
                for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1)
                {
                    if (0 != (l & 1)) { lazy[l] = h(lazy[l], x); ++l; }
                    if (0 != (r & 1)) { --r; lazy[r] = h(lazy[r], x); }
                }
                recalc(a);
                recalc(b);
            }
            public Monoid query(int a, int b)
            {
                thrust(a += sz);
                thrust(b += sz - 1);
                Monoid L = M1, R = M1;
                for (int l = 1, r = b + 1; l < r; l >>= 1, r >>= 1)
                {
                    if (0 != (l & 1)) L = f(L, reflect(l++));
                    if (0 != (r & 1)) R = f(reflect(--r), R);
                }
                return f(L, R);
            }
            public Monoid this[int k] => query(k, k + 1);
        }

    }
}

Measured memory_bytes: 62428