#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int l, r, c;
  vector<vector<pair<int, int> > > v(n + 1, vector<pair<int, int> >());
  for (int i = 2; i <= n; i++) {
    v[i].push_back(pair<int, int>(i - 1, 0));
  }
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> c;
    v[l].push_back(pair<int, int>(r, c));
  }
  vector<int> d(n + 1, -1);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  d[1] = 0;
  for (int i = 0; i < v[1].size(); i++) {
    q.push(pair<int, int>(v[1][i].second, v[1][i].first));
  }
  int i = 0;
  while (!q.empty()) {
    pair<int, int> t = q.top();
    q.pop();
    int ima = t.second;
    int cost = t.first;
    if (d[ima] != -1 && cost >= d[ima]) continue;
    d[ima] = cost;
    for (int i = 0; i < v[ima].size(); i++) {
      int next = v[ima][i].first;
      int next_c = d[ima] + v[ima][i].second;
      if (d[next] == -1 || next_c < d[next]) {
        q.push(pair<int, int>(next_c, next));
      }
    }
  }
  cout << d[n] << endl;
  return 0;
}
