#include <bits/stdc++.h>
using namespace std;
struct edge {
  pair<int, int> p;
  int cost;
};
bool comp(const edge& e1, const edge& e2) { return e1.p < e2.p; }
int main() {
  int n, m;
  cin >> n >> m;
  int l, r, c;
  edge es[100999];
  long long d[100999];
  for (int i = 0; i < (n); i++) d[i] = 1000000000000000;
  d[0] = 0;
  for (int i = 0; i < (m); i++) {
    cin >> l >> r >> c;
    es[i].p = pair<int, int>(l, r);
    es[i].cost = c;
  }
  sort(es, es + m, comp);
  for (int i = 0; i < (m); i++) {
    l = es[i].p.first;
    r = es[i].p.second;
    c = es[i].cost;
    for (int j = 0; j < (r - l); j++) {
      d[l + j] = min(d[l + j], d[l - 1] + c);
    }
  }
  if (d[n - 1] >= 1000000000000000)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
  return 0;
}
