#include <bits/stdc++.h>
using namespace std;
long long N, M;
vector<vector<pair<long long, long long>>> G;
long long d[100000];
int main() {
  cin >> N >> M;
  G.resize(N);
  for (int i = 1; i < N; i++) G[i].push_back({i - 1, 0});
  for (int i = 0; i < M; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    G[l - 1].push_back({r - 1, c});
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  pq.push({0, 0});
  for (int i = 0; i < N; i++) d[i] = -1;
  while (d[N - 1] < 0 && !pq.empty()) {
    pair<long long, long long> p = pq.top();
    pq.pop();
    long long n = p.first;
    long long c = p.second;
    if (d[n] >= 0) continue;
    d[n] = c;
    for (auto &e : G[n]) {
      if (d[e.first] >= 0) continue;
      pq.push({e.first, d[n] + e.second});
    }
  }
  cout << d[N - 1] << endl;
  return 0;
}
