#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll inf = 1ll << 60ll;
ll n, m;
vector<pair<ll, ll> > g[100005];
ll min_cost[100005];

int main() {
	cin >> n >> m;
	
	for (int i = 1; i < n; i++) {
		g[i + 1].push_back({0, i});
	}
	
	for (int i = 1; i <= n; i++) {
		min_cost[i] = inf;
	}
	
	for (int i = 0; i < m; i++) {
		ll s, t, c;
		
		cin >> s >> t >> c;
		g[s].push_back({c, t});
	}
	
	priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > p_que;
	
	p_que.push({0, 1});
	min_cost[1] = 0;
	while (!p_que.empty()) {
		ll pos = p_que.top().second;
		ll cos = p_que.top().first;
		p_que.pop();
		
		for (int i = 0; i < g[pos].size(); i++) {
			ll npos = g[pos][i].second;
			ll ncos = cos + g[pos][i].first;
			
			if (min_cost[npos] > ncos) {
				min_cost[npos] = ncos;
				p_que.push({ncos, npos});
			}
		}
	}
	
	if (min_cost[n] == inf) cout << -1 << endl;
	else cout << min_cost[n] << endl;
	
	return 0;
}