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

const long long MAXN = 1e5 + 10, inf = 1e18 + 10;

long long n, m;
long long l, r, c;
long long d[MAXN];
set <pair <long long, long long> > st;
vector <pair <long long, long long> > adj[MAXN];

void dijk() {
	for (int i = 2; i <= n; i++)
		d[i] = inf;
    d[1] = 0;
    
	st.insert({0, 1});

	while (st.size()) {
		int x = st.begin() -> second;
		st.erase(st.begin());
		for (auto y: adj[x])
			if (d[y.first] > d[x] + y.second) {
				st.erase({d[y.first], y.first});
				d[y.first] = d[x] + y.second;
				st.insert({d[y.first], y.first});
			}
	}
}

int main() {
    cin >> n >> m;
    for (int i = n; i > 1; i--)
        adj[i].push_back({i - 1, 0});
   
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> c;
        adj[l].push_back({r, c});
    }
    dijk();
    if (d[n] == inf)
        cout << -1 << '\n';
    else
        cout << d[n] << '\n';
    return 0;
}