#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<pair<pair<int, int>, int>> v(M);
  for (int i = 0; i < M; i++) {
    int L, R, C;
    cin >> L >> R >> C;
    v[i] = make_pair(make_pair(L, R), C);
  }
  sort(v.begin(), v.end());
  vector<int> L(M), R(M);
  vector<long long> C(M);
  for (int i = 0; i < M; i++) {
    L[i] = v[i].first.first;
    R[i] = v[i].first.second;
    C[i] = v[i].second;
  }
  vector<long long> d(N, 10000000001LL);
  d[0] = 0;
  for (int i = 0; i < M; i++) {
    for (int j = L[i] - 1; j <= R[i] - 1; j++)
      d[j] = min(d[j], d[L[i] - 1] + C[i]);
  }
  if (d[N - 1] == 10000000001LL)
    cout << -1 << endl;
  else
    cout << d[N - 1] << endl;
  return 0;
}
