#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
#define rep(i,n) for (int i=0; i < int(n); i++)
using namespace std;
#define INF 1ll << 50;
#define MAX_V 100005

struct edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

ll V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> V;
    ll E;
    cin >> E;
    for (ll i=0; i<E; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        edge e = {b, c};
        G[a].push_back(e);
    }
    for (ll i = V-1; i > 0; --i) {
        edge e = {i-1,0};
        G[i].push_back(e);
    }
    dijkstra(0);
    if(d[V - 1] == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << d[V - 1] << endl;
}
