#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
struct edge {
  int to;
  long long cost;
  edge(int t, long long c) : to(t), cost(c){};
};
using P = pair<int, long long>;
int N;
vector<vector<edge>> G;
vector<long long> d;
vector<int> par;
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  d = vector<long long>(N, longinf);
  par = vector<int>(N, -1);
  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 < (int)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));
        par[e.to] = v;
      }
    }
  }
}
int main() {
  int M;
  cin >> N >> M;
  G = vector<vector<edge>>(N);
  for (int i = (int)(0); i < (int)(N); i++)
    if (i) G[i].push_back(edge(i - 1, 0));
  for (int i = (int)(0); i < (int)(M); i++) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    --l;
    --r;
    G[l].push_back(edge(r, c));
  }
  dijkstra(0);
  cout << (d[N - 1] == longinf ? -1 : d[N - 1]) << endl;
  return 0;
}
