#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

vector<ll> dijkstra(vector<vector<pair<int,int>>>& graph,int s){
    int n=(int)graph.size();
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    vector<ll> dist(n,LINF);
    dist[s]=0;
    pq.push({0,s});
    while(pq.size()){
        auto p=pq.top();
        pq.pop();
        int v=p.second;
        if(dist[v]<p.first)continue;
        for(auto edge:graph[v]){
            int u=edge.first;
            int w=edge.second;
            if(dist[v]+w<dist[u]){
                dist[u]=dist[v]+w;
                pq.push({dist[u],u});
            }
        }
    }
    return dist;
}

int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<pair<int,int>>> g(n);
    for(int i=0;i<n-1;i++){
        g[i+1].push_back({i,0});
    }
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        g[a].push_back({b,c});
    }
    vector<ll> d=dijkstra(g,0);
    cout<<(d[n-1]==LINF?-1:d[n-1])<<endl;
}