#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long int to;
  long long int cost;
};
bool exist[100001];
vector<edge> G[100001];
long long int d[100001];
long long int n, m;
void dijkstra(long long int start) {
  for (long long int i = 1; i <= n; i++) {
    d[i] = LLONG_MAX;
  }
  d[start] = 0;
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      que;
  que.push(pair<long long int, long long int>(0, start));
  while (!que.empty()) {
    pair<long long int, long long int> p = que.top();
    que.pop();
    long long int cur_v = p.second;
    if (d[cur_v] < p.first) {
      continue;
    }
    for (long long int i = 0; i < (long long int)G[cur_v].size(); i++) {
      edge e = G[cur_v][i];
      if (d[e.to] > d[cur_v] + e.cost) {
        d[e.to] = d[cur_v] + e.cost;
        que.push(pair<long long int, long long int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  long long int l[m], r[m], c[m];
  for (long long int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
  };
  for (long long int i = 0; i < m; i++) {
    edge e1 = {r[i], c[i]};
    G[l[i]].push_back(e1);
    for (long long int j = r[i]; j >= l[i] + 2; j--) {
      if (exist[j]) continue;
      edge e = {j - 1, 0};
      G[j].push_back(e);
      exist[j] = true;
    }
  }
  dijkstra(1);
  if (d[n] == LLONG_MAX)
    cout << -1 << endl;
  else
    cout << d[n] << endl;
}
