#include <bits/stdc++.h>
using namespace std;
int MAX_N = 100010;
long long INF = 1LL << 60;
vector<vector<pair<int, int>>> edges(MAX_N);
vector<long long> dist(MAX_N, INF);
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  dist[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 (dist[v] < p.first) continue;
    for (int i = 0; i < edges[v].size(); ++i) {
      pair<int, int> e = edges[v][i];
      if (dist[e.first] > dist[v] + e.second) {
        dist[e.first] = dist[v] + e.second;
        que.push(pair<int, int>(dist[e.first], e.first));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    edges[l - 1].push_back(pair<int, int>(r - 1, c));
  }
  for (int i = 1; i < n; ++i) edges[i].push_back(pair<int, int>(i - 1, 0));
  dijkstra(0);
  cout << (dist[n - 1] < INF ? dist[n - 1] : -1) << endl;
  return 0;
}
