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