#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<pair<int, int>, int>> LRC(N);
  for (int i = 0; i < (M); i++) {
    cin >> LRC[i].first.first >> LRC[i].first.second >> LRC[i].second;
    LRC[i].first.first--;
    LRC[i].first.second--;
  }
  vector<vector<int>> G(N);
  vector<vector<ll>> CO(N);
  vector<ll> D(N, -1);
  vector<bool> done(N, false);
  priority_queue<pair<ll, int>> q;
  for (int i = 0; i < (M); i++) {
    G[LRC[i].first.first].push_back(LRC[i].first.second);
    CO[LRC[i].first.first].push_back(LRC[i].second);
  }
  for (int i = 0; i < (N - 1); i++) {
    G[i + 1].push_back(i);
    CO[i + 1].push_back(0);
  }
  D[0] = 0;
  q.push({0, 0});
  while (!q.empty()) {
    pair<ll, int> doneNode = q.top();
    q.pop();
    if (done[doneNode.second]) continue;
    done[doneNode.second] = true;
    for (int i = 0; i < ((int)G[doneNode.second].size()); i++) {
      int to = G[doneNode.second][i];
      ll cost = D[doneNode.second] + CO[doneNode.second][i];
      if (D[to] == -1 || cost < D[to]) {
        D[to] = cost;
        q.push({cost, to});
      }
    }
  }
  cout << D[N - 1] << endl;
  return 0;
}
