#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<long long>> way(n, vector<long long>(2));
  vector<tuple<int, int, long long>> path;
  vector<vector<int>> reach(n, vector<int>());
  for (int(i) = (0); (i) < (m); i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    --l;
    --r;
    path.emplace_back(r, l, c);
    for (int j = l; j < r + 1; ++j) {
      reach[j].push_back(i);
    }
  }
  vector<long long> d(n, 100000000000000);
  d[n - 1] = 0;
  long long now = n - 1;
  for (int i = n - 1; i >= 0; --i) {
    int sz = reach[i].size();
    for (int j = 0; j < sz; ++j) {
      d[get<1>(path[reach[i][j]])] =
          min(d[get<1>(path[reach[i][j]])], d[i] + get<2>(path[reach[i][j]]));
    }
  }
  if (d[0] == 100000000000000)
    cout << -1 << endl;
  else
    cout << d[0] << endl;
}
