#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, m;
vector<pair<int, int>> edge[100010];
vector<long long> dijkstra(int x) {
  vector<long long> dist(n + 1, INF);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  dist[x] = 0;
  q.push(pair<int, int>(0, x));
  while (!q.empty()) {
    long long d = q.top().first;
    long long p = q.top().second;
    q.pop();
    if (dist[p] < d) continue;
    for (pair<int, int> next : edge[p]) {
      long long to = next.first;
      long long co = next.second;
      if (dist[p] + co >= dist[to]) continue;
      dist[to] = dist[p] + co;
      q.push(pair<int, int>(dist[to], to));
    }
  }
  return dist;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    edge[l].push_back(pair<int, int>(r, c));
  }
  for (int i = 0; i < (n - 1); ++i) {
    edge[i + 1].push_back(pair<int, int>(i, 0));
  }
  vector<long long> dist = dijkstra(1);
  if (dist[n] != INF)
    cout << dist[n] << endl;
  else
    cout << -1 << endl;
}
