#include<iostream>
#include<vector>
#include<queue>
#include<functional>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int N, M;
vector<vector<P>> E;
ll d[100000];
const ll INF = 1145141919810893;

void djk() {
	for (int i = 0; i < N; i++)d[i] = INF;
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P>> pq;
	pq.push(P(0, 0));
	while (pq.size()) {
		auto now = pq.top(); pq.pop();
		if (now.first > d[now.second])continue;
		for (int i = 0; i < E[now.second].size(); i++) {
			int nxt = E[now.second][i].first;
			ll cost = E[now.second][i].second;
			if (d[nxt] > d[now.second] + cost) {
				d[nxt] = d[now.second] + cost;
				pq.push(P(d[nxt], nxt));
			}
		}
	}
}

int main() {
	cin >> N >> M;
	E.resize(N);
	for (int i = 1; i < N; i++) {
		E[i].push_back(P(i - 1, 0));
	}
	for (int i = 0; i < M; i++) {
		int L, R;
		ll C;
		cin >> L >> R >> C;
		L--, R--;
		E[L].push_back(P(R, C));
	}

	djk();
	if (d[N - 1] == INF)cout << -1 << endl;
	else cout << d[N - 1] << endl;
	return 0;
}