#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int N, M;
	cin >> N >> M;

    vector<tuple<int, int, ll>> LRC(M);
    int l, r;
    ll c;
    rep(i, M) {
        cin >> l >> r >> c;
        --l, --r;
        LRC[i] = forward_as_tuple(l, r, c);
    }
    sort(all(LRC));

    vector<ll> dp(N, LINF);
    dp[0] = 0;

    rep(i, M) {
        tie(l, r, c) = LRC[i];
        // cout << l << r << c << endl;
        if (dp[l] == LINF) continue;
        for (int j = r; j > l; j--) {
            if (dp[j] > dp[l] + c) dp[j] = dp[l] + c;
            else break;
        }       
    }

    // rep(j, N) cout << dp[j] << ' ';

    if (dp[N-1] == LINF) cout << -1 << endl;
    else cout << dp[N-1] << endl;
	return 0;
}
