#include<bits/stdc++.h>

using namespace std;

int main(void) {
    long n, m;
    cin >> n >> m;

    vector<vector<pair<long,long>>> G(n);

    for(int i=0; i<m; i++) {
        long l, r, c;
        cin >> l >> r >> c;
        l--, r--;
        G[l].push_back({r, c});
    }
    for(int i=0; i<n-1; i++)
        G[i+1].push_back({i, 0});

    priority_queue<pair<long,long>> q;
    q.push({0, 0});

    vector<long> dis(n, 1e15);
    while(!q.empty()) {
        auto t = q.top(); q.pop();
        long d = -t.first;
        long v = t.second;
        if(dis[v] <= d) continue;
        dis[v] = d;

        for(auto w: G[v]) {
            if(dis[w.first] <= d + w.second) continue;
            q.push({-(d + w.second), w.first});
        }
    }
    cout << (dis[n-1] == 1e15 ? -1 : dis[n-1]) << endl;
}
