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

using ll = long long;
const ll INF = 1e18;

const int MAXN = 1.1e5;
const int MAXM = 1.1e5;

int N, M, V;

vector<pair<int, int>> adj[MAXN];
ll dist[MAXN];

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> N >> M;
	for (int i = 0; i+1 < N; i++) {
		adj[i+1].emplace_back(i, 0);
	}
	for (int i = 0; i < M; i++) {
		int l, r, c; cin >> l >> r >> c; l--, r--;
		adj[l].emplace_back(r, c);
	}

	for (int i = 0; i < N; i++) {
		dist[i] = INF;
	}
	dist[0] = 0;
	priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
	pq.emplace(0, 0);
	while (!pq.empty()) {
		ll d; int cur; tie(d, cur) = pq.top();
		pq.pop();
		if (d != dist[cur]) continue;
		for (auto it : adj[cur]) {
			int nxt = it.first;
			ll nd = it.second + d;
			if (nd < dist[nxt]) {
				dist[nxt] = nd;
				pq.emplace(nd, nxt);
			}
		}
	}

	ll ans = dist[N-1];
	if (ans == INF) {
		ans = -1;
	}
	cout << ans << '\n';

	return 0;
}
