#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{ll to,cost;};
int V,E;
const ll INF =1234567890123456;
vector<edge>g[100005];
ll d[100005];

void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d, d + V+3, INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		ll 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));
			}
		}
	}
	return;
}
int main(){
	cin>>V>>E;
	for(int i=0;i<E;i++){
		ll a,b,c;
		cin>>a>>b>>c;
		g[a].push_back(edge{b,c});
	}
  for(int i=1;i<V;i++){
    g[i+1].push_back(edge{i,0});
  }
	dijkstra(1);
	if(d[V]==INF)cout<<-1<<endl;
	else cout<<d[V]<<endl;
}
