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

#define MX 100050
#define INF 0x7f7f7f7f7f7f7f7fll
typedef long long ll;
struct edge {
	int v; ll w;
	edge(int v = 0, ll w = 0) : v(v), w(w) {}
	bool operator < (const edge& rhs) const { return w > rhs.w; }
};

vector<edge> g[MX];
ll d[MX];
bool vis[MX];

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 2; i <= n; i++) g[i].push_back(edge(i - 1, 0));
	while(m--) {
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		g[l].push_back(edge(r, c));
	}
	priority_queue<edge> pq;
	pq.push(edge(1, 0));
	for(int i = 2; i <= n; i++) d[i] = INF;
	
	while(pq.size()) {
		edge e = pq.top(); pq.pop();
		int u = e.v;
		if(vis[u]) continue;
		vis[u] = true;
		
		for(auto e : g[u])
			if(d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				pq.push(edge(e.v, d[e.v]));
			}
	}
	if(d[n] == INF) puts("-1");
	else printf("%lld\n", d[n]);
	return 0;
}
