#include <bits/stdc++.h>
using namespace std;

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second

Int INF = 1e18;
//Int mod = 1e9+7;
Int mod = 998244353;

vector<pair<Int, Int>> G[100001];

int main() {
    Int n, m;
    cin >> n >> m;    
    for (Int i = 0; i < m; i++) {
        Int a, b, c;
        cin >> a >> b >> c;
        G[a].emplace_back(b, c);
    }
    for (Int i = 1; i < n; i++) {
        G[i + 1].emplace_back(i, 0);
    }
    vector<Int> d(n + 1, INF);
    d[1] = 0;
    priority_queue<pair<Int, Int>, vector<pair<Int,Int>>, greater<pair<Int, Int>>> q;
    q.push({0, 1});
    while (!q.empty()) {
        pair<Int, Int> p = q.top();
        q.pop();
        Int v = p.se;
        if (d[v] < p.fi) {
            continue;
        }
        for (Int i = 0; i < G[v].size(); i++) {
            pair<Int, Int> to = G[v][i];
            if (d[to.fi] > d[v] + to.se) {
                d[to.fi] = d[v] + to.se;
                q.push({d[to.fi], to.fi});
            }
        }
    }
    dump(d[n] == INF ? -1 : d[n]);
    return 0;
}