#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
struct edge {
  int to;
  long long cost;
};
const long long INF = 1ll << 60;
const int MAX_V = 100000;
int V;
vector<edge> G[MAX_V + 1];
long long d[MAX_V + 1];
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));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  V = n;
  for (int i = 0; i < m; i++) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back(edge{r, c});
  }
  for (int i = 0; i < 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;
}
