#include <bits/stdc++.h>
using namespace std;
int par[int(0x7ffffff)];
int Rank[int(0x7ffffff)];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
    Rank[i] = 0;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (Rank[x] < Rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (Rank[x] == Rank[y]) Rank[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const long long LLINF = pow(2, 61) - 1;
long long N, M;
struct edge {
  long long to, cost;
  edge() {}
  edge(long long to, long long cost) : to(to), cost(cost) {}
};
long long d[10000000];
vector<edge> G[100000];
void dijkstra(long long s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  fill_n(d, N, LLINF);
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    long long 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(pair<int, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int L, R, C;
    cin >> L >> R >> C;
    L--;
    R--;
    G[L].push_back(edge(R, C));
  }
  for (int s = 0; s < N - 1; s++) {
    G[s + 1].push_back(edge(s, 0));
  }
  dijkstra(0);
  if (d[N - 1] == LLINF) {
    cout << -1 << endl;
    return 0;
  }
  cout << d[N - 1] << endl;
}
