#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long siguma(int n){
  return (long long)(n*(n+1)/2);
}
//inf=9223372036854775000;
int main(){
  int x,y,c,n,m,ans=0,l1,l2,l3;
  cin >>n>>m;
  array <array<int,3>,100009> a;
  vector<long> kakehasi(n,0);
 
  vector<bool> ok(n),hontouniok(n); 
  ok[1]=true;ok[0]=true;
  rep(i,m){cin>>x>>y>>c;a[i]={x,y,c};}
  sort(&a[0], &a[m], [](auto& x, auto& y){return x[0] < y[0];});
  rep(i,m){l1=a[i][0];if(ok[l1]){l2=a[i][1];l3=a[i][2];
  for(int i=l1;i<l2+1;i++){
    if(l1==1&&kakehasi[i]>0){kakehasi[i]=min((long)l3,kakehasi[i]);ok[i]=true;}
    else if(l1==1){kakehasi[i]=l3;ok[i]=true;}
    else if(kakehasi[i]==0){kakehasi[i]=l3+kakehasi[l1];ok[i]=true;}
    else {kakehasi[i]=min(kakehasi[i],l3+kakehasi[l1]);ok[i]=true;}
  }
  }
  else break;
  }
  if(kakehasi[n]==0)cout<<-1<<endl;
  else cout<<kakehasi[n]<<endl;
  }