#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> lrc(m);
  for (int i = 0; i < m; i++) {
    int l;
    cin >> l;
    int r;
    cin >> r;
    int c;
    cin >> c;
    get<0>(lrc.at(i)) = l - 1;
    get<1>(lrc.at(i)) = r - 1;
    get<2>(lrc.at(i)) = c - 1;
  }
  sort(lrc.begin(), lrc.end());
  map<int, int> mp;
  int val = 0;
  while (get<0>(lrc.at(val)) == 0) {
    mp[get<1>(lrc.at(val))] =
        min(mp.at(get<1>(lrc.at(val))), get<2>(lrc.at(val)));
    val++;
  }
  while (val < m) {
    for (auto it = mp.begin(); it != mp.end(); it++) {
      if (get<0>(lrc.at(val)) <= it->first) {
        mp[get<1>(lrc.at(val))] =
            min(mp.at(get<1>(lrc.at(val))), get<2>(lrc.at(val)) + (it->second));
      }
    }
    val++;
  }
  if (mp.count(n)) {
    cout << mp.at(n) << endl;
  } else {
    cout << -1 << endl;
  }
}
