/*It was very radiant,
Filled with light, always filled, baby
Everyone cheers,
They cheer again, toward us, yeah
Cause you yeah you
Your appearance, your smile, yeah
Night that has come, oh, that will soak me with a dream
Pulled on to a bright stage that shines in my eyes
I smile toward you like a doll
I have to withstand each dizzying step
This fear that I’ve overcome alone
It shines even brighter, our night

Most of all, this is beautiful
My circus
It gets dizzy in front of my eyes at times
More dangerous it gets, more it heats up
My circus
How much more beautiful would our night be
I’ll throw it at you, my heart

With no hesitation,
I give all of me to you, yeah
I extend my hand, so I can fly toward you
Cause you yeah you
Your two hands, your heart, yeah
Oh, I, oh, if you let me go
Fantasy crumbles, it will end
White clothes flutter, like flower leaves
When it gently blooms again in the distant
Comfortably as if walking on clouds
I’ll go toward you

Most of all, this is beautiful
My circus
It gets dizzy in front of my eyes at times
More dangerous it gets, more it heats up
My circus
How much more beautiful would our night be
I’ll throw it at you, my heart

Say goodnight yeah
Oh yeah oh yeah
Say goodnight yeah
I walk a bit more toward you
Say goodnight yeah
In this night, in this night, baby
Say goodnight yeah
Trust us, baby
White clothes flutter, like flower leaves
When it gently blooms again in the distant
Comfortably as if walking on clouds
I’ll go toward you

Most of all, this is beautiful
My circus
How much more riskier will each night be for us?
Exceptionally shining, my heart*/

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;
using cd = complex<double>;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<cd> vcd;
typedef vector<ii> vii;
typedef vector<vector<int> > vvi;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 1e5 + 5, K = 26, inf = 1e9, infll = 1e18;
const double pi = acos(-1);
vii gr[maxn];
int dist[maxn], n, m;

void Dijkstra(int s){
    int i, j, k, l, r;
    for1(i, 1, n){
        dist[i] = infll;
    }
    dist[s] = 0;
    priority_queue<ii, vii, greater<ii> > pq;
    pq.push(mp(0, s));
    while(!pq.empty()){
        ii t = pq.top();
        pq.pop();
        int du = t.fi, u = t.se;
        if(du != dist[u]) continue;
        fora(v, gr[u]){
            if(dist[v.fi] > dist[u] + v.se){
                dist[v.fi] = dist[u] + v.se;
                pq.push(mp(dist[v.fi], v.fi));
            }
        }
    }
}

void solve(){
    int i, j, k, l, r; cin >> n >> m;
    for1(i, 2, n){
        gr[i].pb(mp(i - 1, 0));
    }
    for1(i, 1, m){
        int u, v, w; cin >> u >> v >> w;
        gr[u].pb(mp(v, w)); 
    }
    Dijkstra(1);
    if(dist[n] >= infll){
        cout << -1; 
    }
    else{
        cout << dist[n];
    }
}

signed main() {
    //freopen(".INP", "r", stdin); 
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}

Measured memory_bytes: 10232