import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop, core.thread;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable INF = 10L^^15;

int N, M;
int[] L, R;
long[] A;

/*
long[] arr;
void init(int n) {
  arr = new long[n];
  arr[] = INF;
}
void rangeAdd(int a, int b, long val) {
  arr[a .. b + 1] += val;
}
long rangeMax(int a, int b) {
  return arr[a .. b + 1].maxElement;
}
//*/

//*
int segN;
long[] segMax, segAdd;
void init(int n) {
  for (segN = 1; segN < n; segN <<= 1) {}
  segMax = new long[segN << 1];
  segAdd = new long[segN << 1];
  segMax[] = -INF;
  segAdd[] = 0;
}
long query(int u, int x, int y, int a, int b, long val) {
// writefln("  query %s [%s, %s) [%s, %s) %s",u,x,y,a,b,val);
  chmax(a, x);
  chmin(b, y);
  if (a >= b) {
    return -INF;
  }
  if (a == x && b == y) {
    segMax[u] += val;
    segAdd[u] += val;
    return segMax[u];
  }
  assert(u < segN);
  const uL = u << 1 | 0;
  const uR = u << 1 | 1;
  const mid = (x + y) >> 1;
  if (segAdd[u] != 0) {
    segMax[uL] += segAdd[u];
    segMax[uR] += segAdd[u];
    segAdd[uL] += segAdd[u];
    segAdd[uR] += segAdd[u];
    segAdd[u] = 0;
  }
  const resL = query(uL, x, mid, a, b, val);
  const resR = query(uR, mid, y, a, b, val);
  segMax[u] = max(segMax[uL], segMax[uR]);
  return max(resL, resR);
}
void rangeAdd(int a, int b, long val) {
  debug {
    writefln("rangeAdd [%s, %s] %s", a, b, val);
  }
  query(1, 0, segN, a, b + 1, val);
}
long rangeMax(int a, int b) {
  debug {
    // writefln("rangeMax [%s, %s]", a, b);
  }
  const res = query(1, 0, segN, a, b + 1, 0);
  debug {
    writefln("rangeMax [%s, %s] = %s", a, b, res);
  }
  return res;
}
//*/

void main() {
  try {
    for (; ; ) {
      N = readInt();
      M = readInt();
      L = new int[M];
      R = new int[M];
      A = new long[M];
      foreach (i; 0 .. M) {
        L[i] = readInt() - 1;
        R[i] = readInt() - 1;
        A[i] = readLong();
      }
      auto ls = new int[][N];
      auto rs = new int[][N];
      foreach (i; 0 .. M) {
        ls[L[i]] ~= i;
        rs[R[i]] ~= i;
      }
      init(N);
      auto dp = new long[N + 1];
      dp[] = -INF;
      dp[0] = 0;
      foreach (x; 0 .. N) {
        rangeAdd(x, x, dp[x] - rangeMax(x, x));
        foreach (i; ls[x]) {
          rangeAdd(0, L[i], +A[i]);
        }
        dp[x + 1] = rangeMax(0, x);
        foreach (i; rs[x]) {
          rangeAdd(0, L[i], -A[i]);
        }
      }
      debug {
        writefln("dp = %s", dp);
      }
      long ans = -INF;
      foreach (x; 0 .. N + 1) {
        chmax(ans, dp[x]);
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
