#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF=1E18+7;
const ll N=1E5+7;
ll n,m;
struct stu{
    ll a,b;
    bool friend operator <(const stu &x,const stu &y){
        return x.b>y.b;
    }
};
vector <stu >ve[N];
bool mark[N];
ll dp[N];
void djstrea(){
    priority_queue<stu>que;
    que.push({1,0});
    dp[1]=0;
    while(que.size()){
        stu x=que.top();
        que.pop();
        if(mark[x.a]) continue ;
        mark[x.a]=1;
        for(ll i=0;i<ve[x.a].size();i++){
            ll dx=ve[x.a][i].a;
            ll dy=ve[x.a][i].b;
            if(dp[dx]>dp[x.a]+dy){
                dp[dx]=dp[x.a]+dy;
                que.push({dx,dp[dx]});
            }
        }
    }
}
int main(){
    cin>>n>>m;
    ll x,y,z;
    for(ll i=1;i<=n;i++) {
        ve[i].push_back({i-1,0});
    }
    for(ll i=0;i<=n;i++) dp[i]=INF;
    for(ll i=1;i<=m;i++){
        cin>>x>>y>>z;
        ve[x].push_back({y,z});
    }
    djstrea();
    if(dp[n]==INF)   cout<<-1<<endl;
    else cout<<dp[n]<<endl;
    return 0;
}
