#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
const int INF = 1e9;
const int MAXV = 100100;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
int V;
vector<edge> G[MAXV];
int d[MAXV];
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));
      }
    }
  }
}
signed main() {
  int n, m;
  cin >> n >> m;
  V = n;
  vector<pair<pii, int>> ps;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back(edge{r, c});
  }
  for (int i = (int)(0); i < (int)(n - 1); ++i) {
    G[i + 1].push_back(edge{i, 0});
  }
  dijkstra(0);
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
}
