#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > G[n];
  vector<long long> dist(n, (long long)1000000007 * 100000);
  vector<bool> used(n, false);
  int l, r, c;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> c;
    G[l - 1].push_back(make_pair(c, r - 1));
  }
  priority_queue<pair<int, int> > q;
  q.push(pair<int, int>(0, 0));
  for (int i = 1; i < n; i++) G[i].push_back(make_pair(0, i - 1));
  while (!q.empty()) {
    long long d;
    long long t;
    tie(d, t) = q.top();
    q.pop();
    dist[t] = d;
    used[t] = true;
    for (pair<int, int> e : G[t]) {
      if (dist[e.second] <= d + e.first) continue;
      q.push(pair<int, int>(d + e.first, e.second));
    }
  }
  if (dist[n - 1] == (long long)1000000007 * 100000) dist[n - 1] = -1;
  cout << dist[n - 1] << endl;
  return 0;
}
