#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long mod = 1e9 + 7;
const int inf = 1 << 30;
const long long lnf = 1ll << 60;
int prevv[100010];
struct edge {
  int to;
  long long cost;
};
vector<long long> dijkstra(int n, vector<vector<edge> > G, int s) {
  fill(prevv, prevv + n, -1);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  vector<long long> dist(n, inf);
  dist[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    int c, v;
    tie(c, v) = que.top();
    que.pop();
    if (dist[v] < c) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      long long nc = e.cost;
      int nv = e.to;
      if (dist[nv] > dist[v] + nc) {
        dist[nv] = dist[v] + nc;
        prevv[nv] = v;
        que.push(pair<int, int>(dist[nv], nv));
      }
    }
  }
  return dist;
}
vector<int> get_path(int t) {
  vector<int> path(0);
  for (; t != -1; t = prevv[t]) path.push_back(t);
  reverse(path.begin(), path.end());
  return path;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<edge> > g(n, vector<edge>(0));
  for (int i = 0; i < (int)(n - 1); i++) {
    g[i + 1].push_back({i, 0});
  }
  for (int i = 0; i < (int)(m); i++) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    l--;
    r--;
    g[l].push_back({r, c});
  }
  vector<long long> dist = dijkstra(n, g, 0);
  long long ans = dist[n - 1];
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << dist[n - 1] << endl;
}
