#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
const int N = 1e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll d[N];
int n, m;
vector<pair<int, ll>> G[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i < n; ++i)
        G[i + 1].emplace_back(i, 0);
    while (m--) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].emplace_back(v, w);
    }
    memset(d, 0x3f, sizeof d);
    d[1] = 0;
    priority_queue<pli, vector<pli>, greater<pli>> pq;
    pq.emplace(0, 1);
    while (pq.size()) {
        auto p = pq.top(); pq.pop();
        ll cur = p.first;
        int u = p.second;
        if (cur > d[u]) continue;
        for (auto e : G[u]) {
            int v = e.first;
            ll w = e.second;
            if (d[v] > cur + w) {
                d[v] = cur + w;
                pq.emplace(d[v], v);
            }
        }
    }
    cout << (d[n] == INF ? -1 : d[n]) << '\n';
}