#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
struct tt {
  long long l, r, c;
};
bool comp(tt &a, tt &b) {
  if (a.l == b.l) {
    return a.r > b.r;
  }
  return a.l < b.l;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  int n, m;
  cin >> n >> m;
  vector<tt> lrc(m);
  for (int i = 0; i < (m); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    lrc[i].l = l;
    lrc[i].r = r;
    lrc[i].c = c;
  }
  sort(lrc.begin(), lrc.end(), comp);
  long long dp[100005];
  fill(dp, dp + 100005, INF);
  dp[0] = 0;
  for (int i = 0; i < (m); ++i) {
    tt cur = lrc[i];
    long long now = dp[cur.l] + cur.c;
    if (dp[cur.r] > now) {
      cout << "debug" << endl;
      memset(dp + cur.l, now, cur.l - cur.r - 1);
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
