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