#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
vector<P> v[100001];
int n,m;
ll ans=1;
ll C[100005]={-1};
string s;
multiset<ll> lset,rset;
ll a[100005];
ll b[100005]={};

int main() {
	cin>>n>>m;
	ll l,r,c;
	rep(i,0,m){
		cin>>l>>r>>c;
		v[r-1].push_back(P(l-1,c));
	}
	rep(i,0,n+1)C[i]=INF;
	C[0]=0;
	rep(i,1,n){
		ll res=INF;
		rep(j,0,v[i].size()){
			res=min(res,C[v[i][j].first]+v[i][j].second);
		}
		C[i]=res;
		for(int j=i-1;j>=0;--j){
			if(C[j]<=res)break;
			C[j]=res;
		}
	}
	if(C[n-1]==INF)cout<<-1<<endl;
	else cout<<C[n-1]<<endl;
	return 0;
}
