#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct edge {
  int to;
  ll cost;
};
vector<edge> g[101010];
int INF = 1010101010;
int main() {
  int n, m;
  cin >> n >> m;
  for (int(i) = 0; (i) < (m); (i)++) {
    int l, r;
    ll c;
    edge e;
    cin >> l >> r >> c;
    l--;
    r--;
    e.to = r;
    e.cost = c;
    g[l].push_back(e);
  }
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    edge ne;
    ne.to = i;
    ne.cost = 0LL;
    g[i + 1].push_back(ne);
  }
  ll ans[n];
  for (int(i) = 0; (i) < (n); (i)++) {
    ans[i] = INF;
  }
  set<std::pair<int, int> > d;
  set<std::pair<int, int> >::iterator it;
  ans[0] = 0LL;
  d.insert(make_pair(0LL, 0));
  while (!d.empty()) {
    it = d.begin();
    std::pair<int, int> tmp = *it;
    d.erase(it);
    for (auto e : g[tmp.second]) {
      if (ans[e.to] > ans[tmp.second] + e.cost) {
        d.insert(make_pair(ans[tmp.second] + e.cost, e.to));
        ans[e.to] = ans[tmp.second] + e.cost;
      }
    }
  }
  cout << ans[n - 1];
  return 0;
}
