#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
struct Edge{ll to,cost;};
vector<Edge> edgeList[100010];
ll d[100010];
int main(){
    cin>>N>>M;
	for(ll i=0;i<M;i++){
		ll l,r,c;cin>>l>>r>>c;
		l--;r--;
		edgeList[l].push_back(Edge{r,c});
	}
	for(ll i=1;i<N;i++){
		edgeList[i].push_back(Edge{i-1,0});
		d[i]=INF;
	}
	d[0]=0;	
	priority_queue<P,vector<P>,greater<P>> pq;
	pq.push(P(0,0));
	while(!pq.empty()){
		ll now=pq.top().second;
		ll nowC=pq.top().first;pq.pop();
		if(nowC>d[now])continue;
		for(auto e:edgeList[now]){
			ll newC=nowC+e.cost;
			if(d[e.to]>newC){
				d[e.to]=newC;
				pq.push(P(newC,e.to));
			}
		}
	}
	cout<<((d[N-1]==INF)?(-1):d[N-1]);
    return 0;
}