#include <bits/stdc++.h>
#include <queue>
using namespace std;
typedef pair<long long, int> P; 
int main(){
	int N, M; cin >> N >> M; 
	long long INF = 1e18; 
	vector<P> E[100010] = {};  
	for(int i = 1; i < N; i++){
		E[i].push_back(make_pair(0LL, i-1)); 
	}
	for(int i = 0; i < M; i++){
		int L, R; long long C; cin >> L >> R >> C; 
		L--; R--; 
		E[L].push_back(make_pair(C, R)); 
	}
	long long dist[100010] = {}; 
	fill(dist+1, dist+N, INF); 
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(make_pair(0LL, 0)); 
	while(que.size()){
		P p = que.top();
		que.pop(); 
		int now = p.second; 
		for(int i = 0; i < E[now].size(); i++){
			if(dist[now] + E[now].at(i).first < dist[E[now].at(i).second]){
				dist[E[now].at(i).second] = dist[now] + E[now].at(i).first;
				que.push(make_pair(dist[now] + E[now].at(i).first, E[now].at(i).second)); 
			}
		}
	}
	if(dist[N-1] == INF) cout << -1 << endl; 
	else cout << dist[N-1] << endl; 
}