//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
typedef long long i64;
typedef i64 T;

typedef pair<int,T> edge;
const T MAXT = LONG_LONG_MAX;

int n, m;

vector<edge> g[MAXN];
T dist[MAXN];

int input() {
	if (scanf("%d %d", &n, &m) < 0) return 0;
	for (int i=0; i<m; i++) {
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		x--, y--;
		g[x].push_back({y, z});
	}
	return 1;
}

void init() {
	for (int i=1; i<n; i++)
		g[i].push_back({i-1, 0});
}

void dijkstra(int source) {
	typedef pair<T,int> node;
	priority_queue<node, vector<node>, greater<node>> q;
	for (int i=0; i<n; i++)
		dist[i] = MAXT;
	dist[source] = 0;
	q.push({0, source});
	while (!q.empty()) {
		node x = q.top();
		q.pop();
		int d = x.first, u = x.second;
		if (d > dist[u])
			continue;
		for (auto &y: g[u]) {
			int v = y.first;
			T w = y.second + d;
			if (w < dist[v]) {
				dist[v] = w;
				q.push({w, v});
			}
		}
	}
}

int solve() {
	dijkstra(0);
	return dist[n-1]==MAXT? -1: dist[n-1];
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
	for (int i=0; i<n; i++) g[i].clear();
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}


