#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
};
long long V, d[200001], INF = 1e12;
vector<edge> G[200001];
int dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  fill(d + 1, d + V + 1, INF);
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<int, int> 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(pair<int, int>(d[e.to], e.to));
    }
  }
}
int main() {
  int n, m, l, r, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> l >> r >> c, G[l].push_back({r, c});
  for (int i = 0; i < n - 1; i++) G[i + 2].push_back({i + 1, 0});
  V = n;
  dijkstra(1);
  if (d[n] == INF) {
    cout << -1;
    return 0;
  }
  cout << d[n];
}
