#include <bits/stdc++.h>
using namespace std;
const int nmax = 100005;
struct edge {
  long long to;
  long long cost;
};
vector<edge> tree[nmax];
long long d[nmax];
long long n;
void dijkstra(long long s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  fill(d, d + n, 1e18);
  d[s] = 0;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    pair<long long, long long> p = pq.top();
    pq.pop();
    long long v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : tree[v]) {
      edge e = x;
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pq.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
int main() {
  long long m;
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    tree[i].push_back(edge{i - 1, 0});
  }
  for (int i = 0; i < m; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    tree[l].push_back(edge{r, c});
  }
  dijkstra(0);
  cout << d[n - 1] << endl;
}
