#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
using namespace std;
typedef pair<int,int> P;
struct edge{int to, cost; };
int n;
vector< edge > g[114514];
int d[114514];
void dijkstra( int s ){
	priority_queue< P, vector<P>, greater<P> > que;
	for(int i=1;i<=n;i++){
		d[i] = LINF;
	}
	d[s] = 0;
	que.push( P(0,s) );
	while( !que.empty() ){
		P p = que.top(); que.pop();
		int v = p.second;
		if( d[v] < p.first ) continue;
		for(int i=0;i<g[v].size();i++){
			edge e = g[v][i];
			if( d[e.to] > d[v] + e.cost ){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}
signed main(){
	cin>>n;
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int l,r,c;
		cin>>l>>r>>c;
		g[l].pb( (edge){r,c} );
	}
	for(int i=2;i<=n;i++){
		g[i].pb( (edge){i-1,0} );
	}
	dijkstra(1);
	if( d[n] == LINF )d[n]=-1;
	cout<<d[n]<<endl;
	return 0;
}