#include <bits/stdc++.h>
using namespace std;
const long long INF = 1001001001001;
struct edge {
  int to;
  int cost;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int v, n;
  cin >> v >> n;
  long long d[v];
  vector<edge> G[v];
  for (int i = 0; i < (n); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, c});
  }
  for (int i = 0; i < (v); i++)
    if (i + 1 < v) G[i + 1].push_back({i, 0});
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 0; i < (v); i++) d[i] = INF;
  d[0] = 0;
  pq.push(pair<int, int>(0, 0));
  while (!pq.empty()) {
    pair<int, int> p = pq.top();
    pq.pop();
    int c = p.second;
    if (d[c] < p.first) continue;
    for (int i = 0; i < (G[c].size()); i++) {
      edge e = G[c][i];
      if (d[e.to] > d[c] + e.cost) {
        d[e.to] = d[c] + e.cost;
        pq.push(pair<int, int>(d[e.to], e.to));
      }
    }
  }
  if (d[v - 1] != INF)
    cout << d[v - 1] << endl;
  else
    cout << -1 << endl;
}
