#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
bool f[303030];
vector<pii>pat[303030];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < num - 1; i++)pat[i + 1].push_back(make_pair(i, 0));
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		pat[za].push_back(make_pair(zb, zc));
	}
	priority_queue<pii>que;
	que.push(make_pair(0, 0));
	for (;;)
	{
		if (que.empty())
		{
			printf("-1\n");
			return 0;
		}
		pii z = que.top();
		que.pop();
		int v = z.second;
		if (f[v])continue;
		if (v == num - 1)
		{
			printf("%lld\n", -z.first);
			return 0;
		}
		f[v] = true;
		for (int i = 0; i < pat[v].size(); i++)que.push(make_pair(z.first - pat[v][i].second, pat[v][i].first));
	}
}