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

long long N, M;
vector<pair<long long, long long> > tree[100005];
long long ans[100005];

int main(){
	cin >> N >> M;

	for(long long i = 0; i < 100005; i++){
		ans[i] = -1;
	}

	for(long long i = 0; i < M; i++){
		long long l, r, c;
		cin >> l >> r >> c; l--; r--;
		tree[l].push_back(make_pair(r, c));
	}

	//                    cost   , point
	priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > > Q;
	Q.push(make_pair(0, 0));

	while(!Q.empty()){
		long long cost = Q.top().first;
		long long point = Q.top().second;
		Q.pop();
		if(ans[point] >= 0){
			continue;
		}
		ans[point] = cost;

		for(long long i = 0; i < tree[point].size(); i++){
			long long nextcost = cost + tree[point][i].second;
			long long nextpoint = tree[point][i].first;
			if(ans[nextpoint] < 0){
				Q.push(make_pair(nextcost, nextpoint));
			}
		}

		if(point > 0 && ans[point - 1] < 0){
			Q.push(make_pair(cost, point - 1));
		}
	}

	cout << ans[N-1] << endl;
}

