#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll N, M, L, R, C;
vector<pair<ll, ll>> g[100010];

int main() {
  cin >> N >> M;
  for(int i = 0; i < M; ++i) {
    cin >> L >> R >> C;
    --L, --R;
    g[L].emplace_back(R, C);
  }
  for(int i = 1; i < N; ++i) 
    g[i].emplace_back(i-1, 0);

  vector<ll> dist(N, INF);
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  dist[0] = 0;
  pq.emplace(0, 0);
  while(pq.size()) {
    ll d = pq.top().first;
    ll v = pq.top().second;
    pq.pop();
    for(auto next : g[v]) {
      ll nv = next.first;
      ll nc = next.second;
      if(dist[nv] > d + nc) {
        dist[nv] = d + nc;
        pq.emplace(dist[nv], nv);
      }
    }
  }
  if(dist[N-1] == INF) cout << -1;
  else cout << dist[N-1];
  return 0;
}