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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct E{
    int to,co;
};

int main() {

    int N,M;
    Scd2(N,M);

    int a,b,c;
    vector<vector<E>> e(N);
    Repe(i,N,1){
        e[i].push_back({i-1,0});
    }
    Rep(i,M){
        Scd3(a,b,c);
        a--,b--;
        e[a].push_back({b,c});
    }

    vl dist(N,1e17);
    dist[0] = 0;
    priority_queue<pll> q;
    q.push({0,0});
    while( q.size() ){
        int from = q.top().second; ll di = q.top().first; q.pop();
        for( E toe : e[from] ){
            int to = toe.to;
            ll co = toe.co;
            if( dist[to] > dist[from] + co ){
                // printf ("%d->%d\n", from, to );
                dist[to] =  dist[from] + co;
                q.push({dist[to],to});
            }
        }
    }

    printf ("%lld\n", dist[N-1]==1e17 ? -1 : dist[N-1] );

    return 0;
}





