#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int64_t>> edges[100000];
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    edges[l - 1].emplace_back(r - 1, c);
  }
  for (int i = 1; i < n; ++i) edges[i].emplace_back(i - 1, 0);
  priority_queue<pair<int, int>> q;
  q.emplace(0, 0);
  bool checked[100000] = {0};
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    if (checked[t.second]) continue;
    checked[t.second] = true;
    if (t.second == n - 1) {
      cout << (-t.first) << endl;
      return 0;
    }
    for (auto to : edges[t.second]) {
      if (checked[to.first]) continue;
      q.emplace(t.first - to.second, to.first);
    }
  }
  cout << -1 << endl;
  return 0;
}
