#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pp;
ll INF = 1e6;
ll n=INF,m;
vector<vector<pp>> graph(n,vector<pp>(0));


ll dijkstra(ll goal){
  priority_queue<pp,vector<pp>,greater<pp>> pq;
  pq.push(make_pair(0,0));
  vector<int> visited(n,0);
  while (!pq.empty()){
    auto now = pq.top();
    pq.pop();
    ll cost,node;
    tie(cost,node) = now;
    if(node == goal){
      return cost;
    }
    if(visited.at(node)==1){
      continue;
    }else{
      visited.at(node) = 1;
      for(auto next:graph.at(node)){
        ll next_cost,next_node;
        tie(next_cost,next_node) = next;
        pq.push(make_pair(cost+next_cost,next_node));
      }
    }
  }
  return -1;
}
      
  
int main() {
  cin >> n >> m;  
  for(int i=1;i<n;i++){
    graph.at(i).push_back(make_pair(0,i-1));
  }
  for(int i=0;i<m;i++){
    ll l,r,c;
    cin >> l >> r >> c;
    graph.at(l-1).push_back(make_pair(c,r-1));
  }
  cout << dijkstra(n-1) << endl;
}
  
  
                          

  