#include <bits/stdc++.h>
using namespace std;
struct e {
  int from;
  int to;
  int cost;
};
vector<pair<int, int>> g[112345];
long long d[112345];
int n;
void dijkstra(int s) {
  for (int i = 0; i <= n + 1; i++) d[i] = 1e18;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      q;
  q.push({0, s});
  while (q.size()) {
    pair<long long, int> p = q.top();
    q.pop();
    if (d[p.second] < p.first) continue;
    d[p.second] = p.first;
    for (pair<int, int> i : g[p.second]) {
      long long nex = d[p.second] + i.second;
      if (d[i.first] < i.second) continue;
      q.push({nex, i.first});
    }
  }
}
int main() {
  int m, l[112345], r[112345], c[112345];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
    g[l[i]].push_back({r[i], c[i]});
  }
  for (int i = 2; i <= n; i++) {
    g[i].push_back({i - 1, 0});
  }
  dijkstra(1);
  if (d[n] == 1e18)
    cout << -1 << endl;
  else
    cout << d[n] << endl;
  return 0;
}
