#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
const long long INF = 1e15;
struct edge {
  int to, cost;
};
vector<edge> G[MAX_N];
long long d[MAX_N];
void init() {
  for (int i = 0; i < MAX_N; i++) {
    d[i] = INF;
  }
}
int main() {
  init();
  int N, M;
  edge e;
  cin >> N >> M;
  for (int i = 0; i < N - 1; i++) {
    e.to = i;
    e.cost = 0;
    G[i + 1].push_back(e);
  }
  for (int i = 0; i < M; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    e.to = r - 1;
    e.cost = c;
    G[l - 1].push_back(e);
  }
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  d[0] = 0;
  Q.push(pair<int, int>(0, 0));
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        Q.push(pair<int, int>(d[e.to], e.to));
      }
    }
  }
  if (d[N - 1] == INF)
    cout << "-1" << endl;
  else
    cout << d[N - 1] << endl;
  return 0;
}
