#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MAX = (1ll << 59);

ll dijkstra(auto& graph){
  int n = graph.size();
  vector<ll> dist(n, MAX);
  vector<bool> fin(n, false);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
  
  pq.push(make_pair(0ll, 0));
  do{
    auto s = pq.top();
    pq.pop();
    fin[s.second] = true;
    for(auto v : graph[s.second]){
      if(fin[v.second]) continue;
      dist[v.second] = min(s.first + v.first, dist[v.second]);
      pq.push(make_pair(dist[v.second], v.second));
    }
  }while(!pq.empty() && !fin[n - 1]);
  
  return dist[n - 1];
}

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<vector<pair<ll, int>>> graph(N);
  
  for(int i = 1; i < N; i++) graph[i].emplace_back(make_pair(0, i - 1));
  
  for(int i = 0; i < M; i++){
    int L, R;
    ll C;
    cin >> L >> R >> C;
    graph[L - 1].emplace_back(make_pair(C, R - 1));
  }
  
  ll dist = dijkstra(graph);
  cout << (dist == MAX ? -1 : dist) << endl;
}