#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<int> > g(N);
	vector<vector<int> > c(N);
	for (int i = 1; i < N; i++) {
		g[i].push_back(i - 1);
		c[i].push_back(0);
	}
	int a, b, C;
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> C;
		a--; b--;
		g[a].push_back(b);
		c[a].push_back(C);
	}

	priority_queue<pair<int, int> > pq;
	int INF = (int)1 << 60;
	vector<int> D(N, INF);
	D[0] = 0;
	pq.push(make_pair(0, 0));

	while (pq.size()) {
		a = pq.top().second;
		pq.pop();

		for (int i = 0; i < g[a].size();i++) {
			if (D[g[a][i]] > D[a] + c[a][i]) {
				D[g[a][i]] = D[a] + c[a][i];
				pq.emplace(-D[g[a][i]], g[a][i]);
			}
		}
	}
	int res = D[N - 1];
	if (res == INF)res = -1;
	cout << res << endl;
}