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

#define LL long long
const int N = 1e5 + 5;
int n, m, l, r, w;
vector<pair<LL, LL>> g[N];
LL d[N]; bool vis[N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> m;
    while(m--) {
        cin >> l >> r >> w;
        g[l].push_back({r, w});
    }   
    for(int i = 1; i <= n; i++) d[i] = 4e18;
    for(int i = 2; i <= n; i++) g[i].push_back({i-1, 0});
    d[1] = 0;
    priority_queue<pair<LL, LL>, vector<pair<LL,LL>>, greater<pair<LL,LL>>> q;
    q.push({0, 1});

    while(!q.empty()) {
        pair<LL, LL> z = q.top();
        q.pop();
        if(z.second == n) {
            cout << z.first;
            return 0;
        }

        if(vis[z.second]) continue;
        vis[z.second] = 1;
        for(auto i : g[z.second]) {
            if(d[i.first] > z.first + i.second) {
                d[i.first] = z.first + i.second;
                q.push({d[i.first], i.first});  
            }
        }
    }
    cout << -1;
}