#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e12;
struct edge {
  int to, cost;
};
int V, E;
vector<vector<edge>> graph;
vector<long long int> d;
void Dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 0; i < V; i++) {
    d[i] = INF;
  }
  d[s] = 0;
  pq.push({0, s});
  pair<int, int> current;
  while (!pq.empty()) {
    current = pq.top();
    pq.pop();
    int v = current.second;
    if (d[v] < current.first) {
      continue;
    }
    for (edge e : graph[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pq.push({d[e.to], e.to});
      }
    }
  }
}
int main() {
  cin >> V >> E;
  graph.resize(V);
  d.resize(V);
  for (int i = 0; i + 1 < V; i++) {
    graph[i + 1].push_back({i, 0});
  }
  for (int i = 0; i < E; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l -= 1;
    r -= 1;
    graph[l].push_back({r, c});
  }
  Dijkstra(0);
  if (d[V - 1] != INF) cout << d[V - 1] << endl;
  if (d[V - 1] == INF) cout << -1 << endl;
  return 0;
}
