#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct edge {
  int to;
  int cost;
};
using P = pair<int, int>;
int V;
vector<edge> G[100001];
long long d[100001];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.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;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  V = N + 1;
  vector<int> L, R, C;
  int l, r, c;
  for (int i = 0; i < M; i++) {
    cin >> l >> r >> c;
    L.push_back(l);
    R.push_back(r);
    C.push_back(c);
  }
  for (int i = N; i > 1; i--) {
    edge e = {i - 1, 0};
    G[i].push_back(e);
  }
  for (int i = 0; i < (int)(M); i++) {
    edge e = {R[i], C[i]};
    G[L[i]].push_back(e);
  }
  dijkstra(1);
  if (d[N] >= INF) {
    cout << -1 << "\n";
  } else {
    cout << d[N] << "\n";
  }
  return 0;
}
