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

const int N = 100005;

int n, m, l, r, c;
vector<pair<int, int>> ve[N];
vector<long long> eve[N];
multiset<long long> se = {0};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    while (m--) {
        cin >> l >> r >> c;
        ve[l].push_back({r, c});
    }
    eve[2].push_back({0});
    for (int i = 1; i <= n; i++) {
        for (long long &v : eve[i]) {
            se.erase(se.find(v));
        }
        if (se.empty()) {
            return cout << -1, 0;
        }
        long long tmp = *se.begin();
        if (i == n) {
            return cout << tmp, 0;
        }
        for (pair<int, int> &v : ve[i]) {
            se.insert(tmp + v.second);
            eve[v.first + 1].push_back(tmp + v.second);
        }
    }
}
