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

using i64 = int64_t;

constexpr i64 INF = 1e18;

struct Edge{
    i64 from, to, cost;
};

struct State{
    i64 num, cost;
    bool operator<(const State &obj)const{
        return cost > obj.cost;
    }
};

using Graph = vector<vector<Edge>>;

int main(){
    int n, m;
    cin >> n >> m;
    Graph graph(n+1, vector<Edge>());
    for(int i=0;i<m;++i){
        i64 l, r, c;
        cin >> l >> r >> c;
        graph[l].push_back({l, r, c});
    }
    for(int i=n;i>0;--i){
        graph[i].push_back({i, i-1, 0});
    }

    vector<i64> mini(n+1, INF);
    mini[1] = 0;
    priority_queue<State> que;
    que.push({1, 0});
    while(!que.empty()){
        auto cur = que.top(); que.pop();
        if(cur.num == n){
            cout << cur.cost << endl;
            return 0;
        }
        for(auto e: graph[cur.num]){
            i64 new_cost = cur.cost + e.cost;
            if(new_cost >= mini[e.to])continue;
            mini[e.to] = new_cost;
            que.push({e.to, new_cost});
        }
    }
    cout << -1 << endl;

    return 0;
}
