#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

template <typename T>
struct edge {
	int to;
	T cost;
	edge(int t, T c) : to(t), cost(c) {}
};
template <typename T>
void dijkstra(const vector<vector< edge<T> >>& G, vector<T>& d, int s) {
	priority_queue<pair<T, int>, vector< pair<T, int> >, greater< pair<T, int> >> que;
	d[s] = 0;
	que.emplace(0, s);

	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		int u = p.second;
		if (d[u] < p.first) { continue; }

		for (auto e : G[u]) {
			if (d[e.to] <= d[u] + e.cost) { continue; }
			d[e.to] = d[u] + e.cost;
			que.emplace(d[e.to], e.to);
		}
	}
}

int main() {
	const Int INF = 1e18;
	int N, M;
	cin >> N >> M;
	vector<vector< edge<Int> >> g(N);
	for (int i = 1; i < N; ++i) {
		g[i].emplace_back(i - 1, 0);
	}
	for (int i = 0; i < M; ++i) {
		int L, R, C;
		cin >> L >> R >> C;
		g[L - 1].emplace_back(R - 1, C);
	}
	
	vector<Int> d(N, INF);
	dijkstra(g, d, 0);
	cout << (d[N - 1] < INF ? d[N - 1] : -1) << endl;

	return 0;
}
