#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
long long n, m, l, r, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  vector<pair<pair<long long, long long>, long long>> v;
  for (long long i = (1); i <= (m); i++) {
    cin >> l >> r >> c;
    v.push_back(make_pair(pair<long long, long long>(l, r), c));
  }
  sort(v.begin(), v.end());
  set<pair<long long, long long>> s;
  set<pair<long long, long long>> t;
  s.insert(pair<long long, long long>(1, 0));
  t.insert(pair<long long, long long>(0, -1));
  for (long long i = (0); i <= (m - 1); i++) {
    long long lbuf = (v[i].first).first;
    long long rbuf = (v[i].first).second;
    long long cbuf = v[i].second;
    auto it = s.lower_bound(pair<long long, long long>(lbuf, 0));
    if (it != s.end()) {
      auto buf = *it;
      cbuf += buf.second;
      auto itritr = t.lower_bound(pair<long long, long long>(-cbuf, -rbuf));
      auto pp = *itritr;
      if (rbuf > -pp.second) {
        s.insert(pair<long long, long long>(rbuf, cbuf));
        t.insert(pair<long long, long long>(-cbuf, -rbuf));
      }
    }
  }
  auto ans_it = s.lower_bound(pair<long long, long long>(n, 0));
  if (ans_it != s.end()) {
    auto ans_buf = *ans_it;
    cout << (ans_buf.second) << endl;
  } else {
    cout << (-1) << endl;
  }
  return 0;
}
