#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
priority_queue<pair<ll,int> > q;
vector<int> g[maxn],w[maxn];
bool vis[maxn];
ll d[maxn];
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)d[i] = 1LL<<60;
	for(int i=1;i<=m;i++){
		int l,r,c;scanf("%d%d%d",&l,&r,&c);
		g[l].pb(r);
		w[l].pb(c);
	}
	for(int i=2;i<=n;i++){
		g[i].pb(i-1);
		w[i].pb(0);
	}
	d[1] = 0;
	q.push(mp(0,1));
	while(!q.empty()){
		int x = q.top().second;q.pop();
		if(vis[x])continue;
		for(int i=0;i<g[x].size();i++){
			int y = g[x][i];
			if(d[y]>d[x]+w[x][i]){
				d[y] = d[x] + w[x][i];
				q.push(mp(-d[y],y));
			}
		}
	}
	if(d[n]==1LL<<60)cout<<-1<<endl;
	else cout << d[n] << endl;
}
