#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e16;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, long long>> v(m);
  for (int i = 0; i < m; i++) {
    int l, r;
    long long C;
    cin >> l >> r >> C;
    l--;
    r--;
    v[i] = make_pair(make_pair(l, r), C);
  }
  sort(v.begin(), v.end());
  vector<long long> d(n, INF);
  d[0] = 0;
  for (int i = 0; i < m; i++) {
    int L = v[i].first.first;
    int R = v[i].first.second;
    long long C = v[i].second;
    for (int j = L; j <= R; j++) {
      d[j] = min(d[j], d[L] + C);
    }
  }
  if (d[n - 1] == INF) {
    cout << -1;
  } else {
    cout << d[n - 1];
  }
  cout << endl;
  return 0;
}
