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

internal partial class Solver {
    public void Run() {
        var n = ni();
        var m = ni();
        var l = new int[m];
        var r = new int[m];
        var a = new int[m];
        for (var i = 0; i < m; i++) {
            l[i] = ni() - 1;
            r[i] = ni() - 1;
            a[i] = ni();
        }
        var tree = new LazySegmentTreeMaxAndAddMonoidOperator().CreateLazySegmentTree();
        tree.Build(n + 1, i => 0);
        tree.LazyUpdate(n, n + 1, a.Sum(x => (long)x));

        var events = Enumerable.Range(0, n).Select(_ => new List<int>()).ToArray();
        for (var i = 0; i < m; i++) {
            events[r[i]].Add(i);
        }
        int head = n;
        for (var i = 0; i < n; i++) {
            // dp[0] = max(dp[0], ... d[n-1]) // choose '0'
            // dp[i] = dp[i-1]                // choose '1'
            var max = tree.Query(head, tree.Count);
            --head;
            tree.LazyUpdate(head, head + 1, max);
            foreach (var j in events[i]) {
                var c = r[j] - l[j] + 1;
                // 0 が c 回連続していたら -a[i] 加算
                // dp[x] -= a[i]; // x >= c
                tree.LazyUpdate(head + c, tree.Count, -a[j]);
            }
        }
        cout.WriteLine(tree.Query(head, tree.Count));
    }
}

/// <summary>
/// 作用素セグメント木
/// </summary>
public interface ILazySegmentTreeMonoidOperator<TMonoid, TOperatorMonoid>
    where TMonoid : struct
    where TOperatorMonoid : struct {
    TMonoid Merge(TMonoid left, TMonoid right);
    TMonoid Apply(TMonoid monoid, int dataNum, TOperatorMonoid operation);
    TOperatorMonoid MergeOperator(TOperatorMonoid current, TOperatorMonoid append);
}

public static class OperatorLazySegmentTreeExtension {
    public static OperatorLazySegmentTree<TMonoid, TOperatorMonoid> CreateLazySegmentTree<TMonoid, TOperatorMonoid>
        (this ILazySegmentTreeMonoidOperator<TMonoid, TOperatorMonoid> lazySegmentTreeMonoidOperator)
        where TMonoid : struct
        where TOperatorMonoid : struct {
        return new OperatorLazySegmentTree<TMonoid, TOperatorMonoid>(lazySegmentTreeMonoidOperator);
    }

    public static bool Check<TMonoid, TOperatorMonoid>
        (this ILazySegmentTreeMonoidOperator<TMonoid, TOperatorMonoid> lazySegmentTreeMonoidOperator, TMonoid m, TOperatorMonoid o1, TOperatorMonoid o2)
    where TMonoid : struct
    where TOperatorMonoid : struct {
        var r1 = lazySegmentTreeMonoidOperator.Apply(lazySegmentTreeMonoidOperator.Apply(m, 1, o1), 1, o2);
        var r2 = lazySegmentTreeMonoidOperator.Apply(m, 1, lazySegmentTreeMonoidOperator.MergeOperator(o1, o2));
        return r1.Equals(r2);
    }
}

public abstract class SegmentTree<TMonoid> where TMonoid : struct {
    protected int N { get; private set; }
    protected TMonoid?[] node;
    protected static int Left(int p) { return p * 2 + 1; }
    protected static int Right(int p) { return p * 2 + 2; }
    public int Count { get; private set; }

    public SegmentTree() { }

    public void Build(IList<TMonoid> array) {
        Build(array.Count, i => array[i]);
    }

    public virtual void Build(int _n, Func<int, TMonoid> create) {
        Count = _n;
        N = 1;
        while (N < _n) {
            N *= 2;
        }

        node = new TMonoid?[2 * N];

        for (int i = 0; i < _n; i++) {
            node[i + N - 1] = create(i);
        }

        for (int i = N - 2; i >= 0; i--) {
            node[i] = Merge(node[Left(i)], node[Right(i)]);
        }
    }

    protected TMonoid? Merge(TMonoid? left, TMonoid? right) {
        if (left != null && right != null) {
            return Merge(left.Value, right.Value);
        }

        if (left == null) {
            return right;
        }

        if (right == null) {
            return left;
        }

        return null;
    }

    protected abstract TMonoid Merge(TMonoid left, TMonoid right);

    public void Update(int index, TMonoid val) {
        int p = index + N - 1;
        node[p] = val;
        while (p > 0) {
            p = (p - 1) / 2;
            node[p] = Merge(node[Left(p)], node[Right(p)]);
        }
    }

    protected virtual TMonoid? Query(int begin, int end, int k, int l, int r) {
        if (r <= begin || end <= l) {
            return null;
        }

        if (begin <= l && r <= end) {
            return node[k];
        }

        int mid = (l + r) / 2;
        return Merge(
            Query(begin, end, Left(k), l, mid),
            Query(begin, end, Right(k), mid, r)
        );
    }

    public TMonoid Query(int begin, int end) {
        return Query(begin, end, 0, 0, N).Value;
    }
};

public class OperatorLazySegmentTree<TMonoid, TOperatorMonoid> : SegmentTree<TMonoid>
    where TMonoid : struct
    where TOperatorMonoid : struct {
    private readonly ILazySegmentTreeMonoidOperator<TMonoid, TOperatorMonoid> monoidOperator;

    private TOperatorMonoid?[] operators;

    public OperatorLazySegmentTree(ILazySegmentTreeMonoidOperator<TMonoid, TOperatorMonoid> lazySegmentTreeMonoidOperator) {
        monoidOperator = lazySegmentTreeMonoidOperator;
    }

    public override void Build(int _n, Func<int, TMonoid> create) {
        base.Build(_n, create);
        operators = new TOperatorMonoid?[2 * N];
    }

    protected override TMonoid Merge(TMonoid left, TMonoid right) {
        return monoidOperator.Merge(left, right);
    }

    protected TOperatorMonoid? MergeOperator(TOperatorMonoid? current, TOperatorMonoid? append) {
        if (current.HasValue && append.HasValue) {
            return monoidOperator.MergeOperator(current.Value, append.Value);
        }

        return current ?? append;
    }

    protected void LazyPropagate(int k, int l, int r) {
        if (!operators[k].HasValue) {
            return;
        }

        if (k < N - 1) {
            int childL = Left(k), childR = Right(k);
            operators[childL] = MergeOperator(operators[childL], operators[k]);
            operators[childR] = MergeOperator(operators[childR], operators[k]);
        }

        node[k] = monoidOperator.Apply(node[k].Value, r - l, operators[k].Value);
        operators[k] = null;
    }

    protected override TMonoid? Query(int begin, int end, int k, int l, int r) {
        LazyPropagate(k, l, r);
        return base.Query(begin, end, k, l, r);
    }

    private void LazyUpdate(
        int begin, int end, TOperatorMonoid @operator, int k, int l, int r) {
        if (r <= begin || end <= l) {
            LazyPropagate(k, l, r);
            return;
        }
        if (begin <= l && r <= end) {
            operators[k] = MergeOperator(operators[k], @operator);
            LazyPropagate(k, l, r);
            return;
        }
        LazyPropagate(k, l, r);
        int mid = (l + r) / 2;
        LazyUpdate(begin, end, @operator, Left(k), l, mid);
        LazyUpdate(begin, end, @operator, Right(k), mid, r);
        node[k] = Merge(node[Left(k)], node[Right(k)]);
    }

    public void LazyUpdate(int begin, int end, TOperatorMonoid @operator) {
        LazyUpdate(begin, end, @operator, 0, 0, N);
    }
}


// example

/// <summary>
/// query       : Max(a1, a2, ... an)
/// range-update: a <- a + Add
/// </summary>
public class LazySegmentTreeMaxAndAddMonoidOperator : ILazySegmentTreeMonoidOperator<long, long> {
    public long Merge(long left, long right) {
        return Math.Max(left, right);
    }

    public long Apply(long monoid, int dataNum, long operation) {
        return monoid + operation;
    }

    public long MergeOperator(long current, long append) {
        return current + append;
    }
}

public class Deque<T> {
    private T[] _buffer;
    private int offset;

    public int Count { get; private set; }
    public Deque(int cap = 10) {
        _buffer = new T[cap];
    }

    public T this[int index] {
        get { return _buffer[GetIndex(index)]; }
        set { _buffer[GetIndex(index)] = value; }
    }

    private int GetIndex(int index) {
        if (index >= Count) {
            throw new IndexOutOfRangeException("out of range");
        }

        var ret = index + offset;
        if (ret >= _buffer.Length) {
            ret -= _buffer.Length;
        }

        return ret;
    }
    public void PushFront(T item) {
        if (Count == _buffer.Length) {
            Extend();
        }

        if (--offset < 0) {
            offset += _buffer.Length;
        }

        _buffer[offset] = item;
        ++Count;
    }
    public T PopFront() {
        if (Count == 0) {
            throw new InvalidOperationException();
        }

        --Count;
        var ret = _buffer[offset++];
        if (offset >= _buffer.Length) {
            offset -= _buffer.Length;
        }

        return ret;
    }
    public void PushBack(T item) {
        if (Count == _buffer.Length) {
            Extend();
        }

        Count++;
        var id = Count + offset;
        if (id >= _buffer.Length) {
            id -= _buffer.Length;
        }

        _buffer[id] = item;
    }
    public T PopBack() {
        if (Count == 0) {
            throw new InvalidOperationException();
        }

        var ret = _buffer[GetIndex(Count - 1)];
        Count--;
        return ret;
    }
    private void Extend() {
        var newBuffer = new T[_buffer.Length << 1];
        if (offset > _buffer.Length - Count) {
            var len = _buffer.Length - offset;
            Array.Copy(_buffer, offset, newBuffer, 0, len);
            Array.Copy(_buffer, 0, newBuffer, len, Count - len);
        } else {
            Array.Copy(_buffer, offset, newBuffer, 0, Count);
        }

        _buffer = newBuffer;
        offset = 0;
    }
}

// PREWRITEN CODE BEGINS FROM HERE
internal partial class Solver : Scanner {
    public static void Main(string[] args) {
#if LOCAL
        var inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
    }
    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

internal static class LinqPadExtension {
    [Conditional("DEBUG")]
    public static void Dump<T>(this T obj) {
#if DEBUG
        LINQPad.Extensions.Dump(obj);
#endif
    }
}

public class Scanner {
    private readonly TextReader Reader;
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    private readonly char[] buffer = new char[2 * 1024];
    private int cursor = 0, length = 0;
    private string Token;
    private readonly StringBuilder sb = new StringBuilder(1024);

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return (int)NextLong(); }
    public long NextLong() {
        var s = Next();
        long r = 0;
        var i = 0;
        var negative = false;
        if (s[i] == '-') {
            negative = true;
            i++;
        }
        for (; i < s.Length; i++) {
            r = r * 10 + (s[i] - '0');
#if DEBUG
            if (!char.IsDigit(s[i])) {
                throw new FormatException();
            }
#endif
        }
        return negative ? -r : r;
    }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        var array = new string[size];
        for (var i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        var array = new int[size];
        for (var i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        var array = new long[size];
        for (var i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        var array = new double[size];
        for (var i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (Token == null) {
            if (!StockToken()) {
                throw new InvalidOperationException();
            }
        }
        var token = Token;
        Token = null;
        return token;
    }

    public bool HasNext() {
        if (Token != null) {
            return true;
        }

        return StockToken();
    }

    private bool StockToken() {
        while (true) {
            sb.Clear();
            while (true) {
                if (cursor >= length) {
                    cursor = 0;
                    if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
                        break;
                    }
                }
                var c = buffer[cursor++];
                if (33 <= c && c <= 126) {
                    sb.Append(c);
                } else {
                    if (sb.Length > 0) {
                        break;
                    }
                }
            }

            if (sb.Length > 0) {
                Token = sb.ToString();
                return true;
            }

            return false;
        }
    }
}

Measured memory_bytes: 55004