#include <bits/stdc++.h>
// #include "../../cxx-prettyprint/prettyprint.hpp"
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

// だれかのWAを直してみる
 
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
typedef int ll;
 
const ll INF = 1e9;
 
struct edge {
    int to;
    int cost;
};
 
// <最短距離, 頂点の番号>
using P = pair<int, int>;
 
int V;
vector<edge> G[100001];
vector<ll> d(100001);

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d.begin(), d.end(), INF);
    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));
            }
        }
    }
}
 
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述
 
	int N, M;
	cin >> N >> M;
 
	V = N+1;
 
	vector<int> L,R,C;
	int l,r,c;
	for(int i=0; i<M; i++){
		cin >> l >> r >> c;
		L.push_back(l);
		R.push_back(r);
		C.push_back(c);
	}
 
	for(int i=N;i>1;i--){
		edge e = {i-1, 0};
		G[i].push_back(e);
	}
	REP(i,M){
		edge e = {R[i], C[i]};
		G[L[i]].push_back(e);
	}
 
	dijkstra(1);
 
	// cout << d << "\n";
 
	cout << setprecision(15);
	
	if(d[N] == INF){
		cout << -1 << "\n";
	}
	else{
		cout << d[N] << "\n";
	}
 
return 0;
}
