#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=1;i<=n;i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
const int MAX=100100;
const ll INF=1001001001001001;

struct edge{
    int to;
    ll cost;
};

int main(){
    int v,n;
    cin >> v >> n;
    ll d[v];
    vector<edge> G[v];
    ll costm[v][v]={};
    rep(i,n){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        for(int j=a;j<=b;j++){
            for(int k=j;k<=b;k++){
                if(c<costm[j][k] || costm[j][k]==0){
                    costm[j][k]=c;
                }
            }
        }
    }
    rep(i,v){
        for(int j=i;j<v;j++){
            if(costm[i][j]>0){
                edge e = {j,costm[i][j]};
                G[i].push_back(e);
            }
        }
    }
    priority_queue<P,vector<P>,greater<P>> pq;
    rep(i,v) d[i]=INF;
    d[0]=0;
    pq.push(P(0,0));
    while(!pq.empty()){
        P p=pq.top();
        pq.pop();
        ll c = p.second;
        if(d[c]<p.first) continue;
        rep(i,G[c].size()){
            edge e = G[c][i];
            if(d[e.to] > d[c]+e.cost){
                d[e.to] = d[c] + e.cost;
                pq.push(P(d[e.to],e.to));
            }
        }
    }
    if(d[v-1]!=INF) cout << d[v-1] << endl;
    else cout << -1 << endl;
}


