#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll INF=1e18;
int n,m;
vector<P>edge[100010];

vector<ll> dijkstra(int x){
  vector<ll>dist(n+1,INF);
  priority_queue<P,vector<P>,greater<P>>q;
  dist[x]=0;
  q.push(P(0,x));
  while(!q.empty()){
    ll d=q.top().first;
    ll p=q.top().second;
    q.pop();
    if(dist[p]<d)continue;
    for(P next:edge[p]){
      ll to=next.first;
      ll co=next.second;
      if(dist[p]+co>=dist[to])continue;
      dist[to]=dist[p]+co;
      q.push(P(dist[to],to));
    }
  }
  return dist;
}

int main(){
  cin>>n>>m;
  rep(i,m){
    int l,r,c; cin>>l>>r>>c;
    edge[l].push_back(P(r,c));
  }
  rep(i,n-1){
    edge[i+1].push_back(P(i,0));
  }
  vector<ll>dist=dijkstra(1);
  if(dist[n]!=INF)cout<<dist[n]<<endl;
  else cout<<-1<<endl;
}