#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ld long double
 
using namespace std;
 
 
const int N = 2e5 + 123;
const int MAXN = 1e5 + 12;
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
 

ll n, m, d[N];
bool vis[N], is[N];
vector <pll> g[N];
 
 
void djk() {
    priority_queue <pair<ll, ll> > q;
    q.push({0, 1});
    pair<ll, ll> tmp;
    ll u, w;
    while (!q.empty()) {
        tmp = q.top();
        q.pop();
        u = tmp.se;
        w = -tmp.f;
        if (vis[u])
            continue;
        vis[u] = 1;
        d[u] = w;
        if (u != 1 && !vis[u - 1])
            q.push({-w, u - 1});
        for (int i = 0; i < g[u].size(); i++)
            if (!vis[g[u][i].f])
                q.push({-w - g[u][i].se, g[u][i].f});
    }
} 
 
 
int main() {
    cin >> n >> m;
    ll x, y, z;
    memset(is, 1, sizeof(is));
    for (int i = 1; i <= m; i++) {
        cin >> x >> y >> z;
        g[x].pb({y, z});
    }
    memset(d, -1, sizeof(d));
    djk();
    cout << d[n];
    return 0;
}