#include <bits/stdc++.h>
using namespace std;

int main() {
  const long inf = 1l << 62;
  int n, m;
  cin >> n >> m;
  vector<long> d(n + 1, inf);
  d.at(1) = 0;
  vector<vector<pair<int, long>>> to(n + 1);
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    to.at(l).emplace_back(r, c);
  }
  for (int i = 2; i < n; i++) {
    to.at(i).emplace_back(i - 1, 0);
  }
  priority_queue<pair<long, int>> q;
  q.emplace(0, 1);
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    int current = t.second;
    for (auto next : to.at(current)) {
      if (d.at(current) + next.second < d.at(next.first)) {
        d.at(next.first) = d.at(current) + next.second;
        q.emplace(-d.at(next.first), next.first);
      }
    }
  }
  if (d.at(n) == inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << d.at(n) << endl;
}
