#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
long long n;
vector<edge> g[114514];
long long d[114514];
void dijkstra(long long s) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  for (long long i = 1; i <= n; i++) {
    d[i] = 100000000000000007LL;
  }
  d[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) continue;
    for (long long i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<long long, long long>(d[e.to], e.to));
      }
    }
  }
}
signed main() {
  cin >> n;
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    g[l].push_back((edge){r, c});
  }
  for (long long i = 2; i <= n; i++) {
    g[i].push_back((edge){i - 1, 0});
  }
  dijkstra(1);
  if (d[n] == 100000000000000007LL) d[n] = 1;
  cout << d[n] << endl;
  return 0;
}
