#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
const ll MAX_D = 10000000000000000LL;

int main(void)
{
	int n, m;
	vector<pair<int, long> > graph[100001];
	// map<P, ll> graph;
	int l[100001], r[100001];
	ll c[100001];
	ll d[100001] = {};
	repp (i, 1, 100001) {
		d[i] = MAX_D;
	}
	cin >> n >> m;
	rep (i, m) {
		cin >> l[i] >> r[i] >> c[i];
		// graph[make_pair(l[i] - 1, r[i] - 1)] = c[i];
		graph[l[i] - 1].push_back(make_pair(r[i] - 1, c[i]));
	}
	repp (i, 1, n) {
		// graph[make_pair(i, i - 1)] = -1;
		graph[i].push_back(make_pair(i - 1, 0));
	}
	// for (auto x : graph) {
	// 	cout << x.first.first << " " << x.first.second << " " << x.second << endl;
	// }

	bool used[100001] = {};
	while (true) {
		// rep (i, n) {
		// 	cout << d[i] << " ";
		// } cout << endl;
		int v = -1;
		for (int u = 0; u < n; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) {
				v = u;
			}
		}
		// cout << v << " " << d[v] << endl;
		if (v == -1) {
			break;
		}
		used[v] = true;
		for (int u = 0; u < n; u++) {
			for (auto x : graph[v]) {
				d[x.first] = min(d[x.first], d[v] + x.second);
			}
			// int x = graph[make_pair(v, u)];
			// if (x != 0) {
				// d[u] = min(d[u], d[v] + (x == -1 ? 0 : x));
			// }
		}
	}
	// rep (i, n) {
	// 	cout << d[i] << " ";
	// }
	if (d[n - 1] >= MAX_D) {
		cout << -1 << endl;
	} else {
		cout << d[n - 1] << endl;
	}

	return 0;
}