#include <bits/stdc++.h>
using namespace std;
const long long prime = 998244353;
const long double PI = 2 * acos(0.0);
int main() {
  const long long inf = 1 << 30;
  long long n, m;
  cin >> n >> m;
  vector<long long> l(m), r(m), c(m), d(n, inf);
  vector<pair<long long, long long> > ls(m);
  for (long long i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
    l[i]--;
    r[i]--;
    ls[i] = std::make_pair(l[i], i);
  }
  d[0] = 0;
  sort(ls.begin(), ls.end());
  long long index, left, right, num;
  for (long long i = 0; i < m; i++) {
    index = ls[i].second;
    left = l[index];
    right = r[index];
    num = d[left] + c[index];
    for (long long j = left + 1; j < right + 1; j++) {
      d[j] = min(d[j], num);
    }
  }
  if (d[n - 1] == inf) {
    cout << -1 << endl;
  } else {
    cout << d[n - 1] << endl;
  }
  return 0;
}
