#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
const int N = 1e5 + 10, inf = 1e18;
int dis[N];
vector < pair <int , int> > g[N];

void dijkstra(int v, int t)
{
    fill(dis, dis + N, inf);
    dis[v] = 0;
    priority_queue < pair <int , int> > pq;
    pq.push({0, v});
    while (pq.size()) {
        v = (pq.top()).S; pq.pop();
        if (v == t) return ;
        for (auto e : g[v]) {
            int u = e.F, w = e.S;
            if (dis[v] + w < dis[u]) {
                dis[u] = dis[v] + w;
                pq.push({-dis[u], u});
            }
        }
    }
}


int32_t main()
{
    int n, m; cin >> n >> m;
    for (int i = 2; i <= n; i ++) g[i].push_back({i - 1, 0});
    for (int i = 0; i < m; i ++) {
        int l, r, w; cin >> l >> r >> w;
        g[l].push_back({r, w});
    }
    dijkstra(1, n);
    cout << (dis[n] == inf ? -1 : dis[n]) << "\n";
}
