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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100009, inf = 1000000000000000000;
int n, m;

vector<pair<int, int>> graph[N];
int d[N];

void nope() {
    cout << -1 << endl;
    exit(0);
}

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    for(int i = 1; i <= n; ++i) d[i] = inf;

    priority_queue<pair<int, int>> pq;
    pq.emplace(0, 1);

    while(!pq.empty()) {
        int w = -pq.top().first, v = pq.top().second; pq.pop();
        if(d[v] == inf) {
            d[v] = w;
            for(auto child : graph[v]) {
                if(d[child.first] == inf) {
                    pq.emplace(-w - child.second, child.first);
                }
            }
        }
    }

    if(d[n] == inf) cout << -1 << endl;
    else cout << d[n] << endl;
    
    return 0;
}
