#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int n, m; cin >> n >> m;
	vector<pair<pair<int, int>, int>> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i].first.second >> a[i].first.first;
		a[i].first.second--;
		cin >> a[i].second;
	}
	auto comp = [](auto a, auto b) {
		if (a.first.first == b.first.first) {
			return a.second < b.second;
		}
		return a.first.first < b.first.first;
	};
	sort(a.begin(), a.end(), comp);
	vector<int> d(n + 2, 1e9);
	d[0] = 0;
	for (int i = 0; i < m; i++) {
		int l = a[i].first.second;
		int r = a[i].first.first;
		int c = a[i].second;
		for (int j = r - 1; j >= l; j--) {
			if (d[j] <= d[l] + c) break;
			d[j] = d[l] + c;
		}
	}
	if (d[n - 1] >= 1e9) cout << -1 << endl;
	else cout << d[n - 1] << endl;
	return 0;
}
