#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct Edge{int to,cost;};
struct Node{
    int v,d;
    bool operator<(const Node&right)const{return d<right.d;}
    bool operator>(const Node&right)const{return d>right.d;}
};
int n,m,l,r,c,d[100009];
vector<Edge> e[100009];

signed main(){
    cin>>n>>m;
    for(int i=1;i<n;i++){
        e[i+1].push_back({i,0});
        d[i+1]=1e18;
    }
    rep(i,m){
        cin>>l>>r>>c;
        e[l].push_back({r,c});
    }
    priority_queue<Node,vector<Node>,greater<Node>> que;
    que.push({1,0});
    while(!que.empty()){
        Node V=que.top();
        que.pop();
        if(d[V.v]<V.d)continue;
        rep(i,e[V.v].size()){
            if(d[e[V.v][i].to]>V.d+e[V.v][i].cost){
                d[e[V.v][i].to]=V.d+e[V.v][i].cost;
                que.push({e[V.v][i].to,d[e[V.v][i].to]});
            }
        }
    }
    cout<<(d[n]<1e18?d[n]:-1)<<endl;
}