#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
  edge() {}
  edge(long long a, long long b) { to = a, cost = b; }
};
long long n, m;
vector<edge> G[100005];
long long dist[100005];
void dijkstra() {
  for (int i = 1; i <= n; i++) dist[i] = 1e18;
  dist[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      Q;
  Q.push(make_pair(0, 1));
  long long v, d;
  while (Q.size()) {
    d = Q.top().first;
    v = Q.top().second;
    Q.pop();
    if (dist[v] < d) continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (dist[G[v][i].to] > d + G[v][i].cost) {
        dist[G[v][i].to] = d + G[v][i].cost;
        Q.push(make_pair(dist[G[v][i].to], G[v][i].to));
      }
    }
  }
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) G[i + 1].push_back(edge(i, 0));
  long long l, r, c;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> c;
    G[l].push_back(edge(r, c));
  }
  dijkstra();
  if (dist[n] > 1e18 / 2) dist[n] = -1;
  cout << dist[n] << endl;
  return 0;
}
