#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000
vector<pair<ll,ll> >g[N];
typedef pair<ll,ll> P;
priority_queue<P,vector<P>,greater<P> >Q;
ll d[N];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<n;i++){
	g[i+1].push_back(make_pair(i,0));
    }
    for(int i=0;i<m;i++){
	ll a,b,c;
	cin>>a>>b>>c;
	g[a].push_back(make_pair(b,c));
    }
    for(int i=1;i<=n;i++)d[i]=1e17;
    Q.push(make_pair(0,1));
    while(!Q.empty()){
	ll x=Q.top().second;
	ll cost=Q.top().first;
	Q.pop();
	if(d[x]<=cost)continue;
	d[x]=cost;
	for(auto y:g[x]){
	    Q.push(make_pair(cost+y.second,y.first));
	}
    }
    if(d[n]==1e17)d[n]=-1;
    cout<<d[n]<<endl;
}

