#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <typename T>
struct edge {
  int to;
  T cost;
  edge(int t, T c) : to(t), cost(c) {}
};
template <typename T>
using Graph = vector<vector<edge<T>>>;
template <typename T>
void dijkstra(int s, T inf, vector<T> &d, Graph<T> &G) {
  priority_queue<pair<int, T>, vector<pair<int, T>>, greater<pair<int, T>>> que;
  fill((d).begin(), (d).end(), inf);
  d[s] = 0;
  que.push(make_pair(0, s));
  while (!que.empty()) {
    pair<int, T> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(make_pair(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  Graph<ll> G(N, vector<edge<ll>>());
  for (int(i) = 0; (i) < (M); (i)++) {
    int l, r;
    ll c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].push_back(edge<ll>(r, c));
  }
  for (int i = N - 1; i > 0; i--) {
    G[i].push_back(edge<ll>(i - 1, 0));
  }
  vector<ll> dist(N);
  dijkstra<ll>(0, LINF, dist, G);
  cout << (dist[N - 1] == LINF ? -1 : dist[N - 1]) << endl;
  return 0;
}
