#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000;
struct edge {
  long long to, cost;
};
const long long MAXV = 100005;
vector<vector<edge>> G(MAXV);
vector<long long> d(MAXV, INF);
void dijkstra(long long s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  d[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> 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<long long, long long>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < n - 1; i++) G[i + 1].push_back(edge{i, 0LL});
  for (int i = 0; i < m; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    G[--l].push_back(edge{--r, c});
  }
  dijkstra(0);
  if (d[n - 1] != INF)
    cout << d[n - 1] << endl;
  else
    cout << -1 << endl;
}
