#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
int V, E;
const long long INF = 1234567890123456;
vector<edge> g[100005];
long long d[100005];
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  fill(d, d + V + 3, INF);
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<int, int> 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<int, int>(d[e.to], e.to));
      }
    }
  }
  return;
}
int main() {
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    g[a].push_back(edge{b, c});
  }
  for (int i = 1; i < V; i++) {
    g[i + 1].push_back(edge{i, 0});
  }
  dijkstra(1);
  if (d[V] == INF)
    cout << -1 << endl;
  else
    cout << d[V] << endl;
}
