/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<ll> dijkstra(vector<vector<pair<int,int>>>& edge, int start){
    int n = edge.size();
    vector<ll> dist(n,INF);
    dist[0]=0;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    pq.emplace(0,0);
    while(pq.size()){
        auto p = pq.top();pq.pop();
        if(dist[p.second]<p.first)continue;
        for(auto to: v[p.second]){
            if(dist[to.first]>dist[p.second]+to.second){
                dist[to.first]=dist[p.second]+to.second;
                pq.emplace(dist[to.first],to.first);
            }
        }
    }
    return dist;
}
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<vector<pair<int,int>>> edge(N);
    int l,r,c;
    REP(i,M){
        cin >> l >> r >> c;
        l--;r--;
        edge[l].push_back(mp(r,c)); 
    }
    REP(i,N-1) edge[i+1].push_back(mp(i,0)); //重み0の辺
    auto dist = dijkstra(edge, 0);

    if (dist[N-1]>=inf) cout << -1 << endl;
    else cout << dist[N-1]<< endl;
}
