#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  vector<long long> C(M);
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> C[i];
    L[i]--;
    R[i]--;
  }
  vector<vector<pair<int, long long>>> e(N);
  for (int i = 0; i < M; i++) {
    e[L[i]].push_back(make_pair(R[i], C[i]));
  }
  for (int i = 1; i < N; i++) {
    e[i].push_back(make_pair(i - 1, 0LL));
  }
  vector<long long> d(N, 10000000000LL);
  priority_queue<pair<long long, int>> q;
  q.push(make_pair(0LL, 0));
  while (!q.empty()) {
    pair<long long, int> t = q.top();
    q.pop();
    int index = t.second;
    if (d[index] <= t.first) continue;
    d[index] = t.first;
    for (int i = 0; i < e[index].size(); i++) {
      q.push(make_pair(d[index] + e[index][i].second, e[index][i].first));
    }
  }
  if (d[N - 1] == 10000000000LL)
    cout << -1 << endl;
  else
    cout << d[N - 1] << endl;
  return 0;
}
