#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using P = pair<long long, long long>;
struct edge {
  long long to;
  long long cost;
};
vector<edge> G[200000];
vector<long long> d(200000, 1e+9);
void dijkstra(long long s) {
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P 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(P(d[e.to], e.to));
      }
    }
  }
}
signed main(void) {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, 1e+9);
  a[0] = 0;
  vector<tuple<long long, long long, long long>> data(m);
  for (long long(i) = 0; (i) < (m); (i)++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    data[i] = make_tuple(a, b, c);
    struct edge e = {b, c};
    G[a].push_back(e);
  }
  for (long long(i) = ((n)-1); (i) >= 0; (i)--) {
    if (i == 0) break;
    G[i].push_back({i - 1, 0});
  }
  dijkstra(0);
  cout << d[n - 1] << endl;
}
