#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vector<pair<pii,int>> A(M);
  rep(i,0,M) cin>>A[i].first.first>>A[i].first.second>>A[i].second;
  sort(ALL(A));
  vi dp(N+1,-1);
  dp[1]=0;
  priority_queue<pii,vector<pii>,greater<pii>> Q;
  int memo=0;
  REP(i,1,N){
    for(memo;memo<M;memo++){
      if(A[memo].first.first>i) break;
      Q.push(mp(A[memo].first.second,A[memo].second));
    }
    while(Q.size()>0){
      int X=Q.top();
      if(X>i) break;
      Q.pop();
    }
    if(dp[i]!=-1){
      queue<pii> q;
      rep(i,0,Q.size()){
        q.push(Q.top());
        int X=Q.top().first,Y=Q.top().second;
        Q.pop();
        if(dp[X]==-1) dp[X]=Y+dp[i];
        else dp[X]=min(dp[X],Y+dp[i]);
      }
      while(q.size()>0){
        Q.push(q.front());
        q.pop();
      }
    }
  }
  cout<<dp[N]<<endl;
  }
