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


int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, ll>>> edge(N+1, vector<pair<int, ll>>());
    for (int i = 0; i < M; i++) {
        ll l, r, c;
        cin >> l >> r >> c;
        edge[l].push_back({r, c});
    }
    for (int i = 2; i <= N; i++) {
        edge[i].push_back({i-1, 0});
    }
    
    ll inf = LLONG_MAX;
    
    
    vector<ll> dist(N+1, inf);
    dist[1] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
    q.push({0, 1});
    while(!q.empty()) {
        int now = q.top().second;
        q.pop();
        for (auto p : edge[now]) {
            int nxt = p.first;
            ll c = p.second;
            if (dist[now] + c >= dist[nxt]) continue;
            dist[nxt] = dist[now] + c;
            q.push({dist[nxt], nxt});
        }
    }
    
    if (dist[N] == inf) cout << -1 << endl;
    else cout << dist[N] << endl;
    
    return 0;
}
