#include <cstdio>
#include <iostream>
using namespace std;
typedef long long int ll;
const ll inf = 9223372036854775807;
ll n,s,a,b,c;
ll m[100000][100000];
ll dis[100000];
int main(){
    cin >> n >> s;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            m[i][j] = inf;
            m[i][i] = 0;
        }
    }
    for(int i = 1; i <= s; i++){
        cin >> a >> b >> c;
        for(int p = a; p <= b - 1; p++){
            for(int k = p + 1; k <= b; k++){
                if(m[p][k] > c){
                    m[p][k] = c;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        dis[i] = m[1][i];
    }
    int num;
    int s = 2;
    while(s <= n){
    for(int i = s; i <= n; i++){
    ll min = inf;
        if(dis[i] < min){
            min = dis[i];
            num = i;
        }
        for(int i = 1; i <= n; i++){
            if((m[num][i] != inf) && (m[num][i] != 0) && (dis[i] >= dis[num]+m[num][i])){
                    dis[i] = dis[num] + m[num][i];
            }
        }
    }
        s++;
    }
    //  for(int i = 1; i <= n; i++){
    //     cout << dis[i] << ' ';
    // }
    // cout << endl;
    if(dis[n] == inf) {
        cout << -1 << endl;
    }
    else {
        cout << dis[n] << endl;
    }
    return 0;
}