#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nmax=100005;
struct edge{ll to;ll cost;};
vector<edge> tree[nmax];
ll d[nmax];
ll n;
void dijkstra(ll s){
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  fill(d,d+n,1e18);
  d[s]=0;
  pq.push(make_pair(0,s));
  while(!pq.empty()){
    pair<ll,ll> p=pq.top();
    pq.pop();
    ll v=p.second;
    if(d[v]<p.first){
      continue;
    }
    for(auto x:tree[v]){
      edge e=x;
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pq.push(make_pair(d[e.to],e.to));
      }
    }
  }
}
int main(){
  ll m;cin >> n >> m;
  for(int i=1;i<n;i++){
    tree[i].push_back(edge{i-1,0});
  }
  for(int i=0;i<m;i++){
    ll l,r,c;cin >> l >> r >> c;
    l--,r--;
    tree[l].push_back(edge{r,c});
  }
  dijkstra(0);
  if(d[n-1]==1e18){
    cout << -1 << endl;
  }
  else{
    cout << d[n-1] << endl;
  }
}