#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

struct bit{
   ll val[N];
   void init(){
      memset(val,0x3f,sizeof val);
   }
   void upd(int x,ll v){
      for(;x < N;x += (x&(-x)))val[x] = min(val[x],v);
   }
   inline ll query(int x){
      ll res = 0x3f3f3f3f3f3f3f3fLL;
      for(;x;x -= (x&(-x)))res = min(res,val[x]);
      return res;
   }
}s;

struct query{
   int l,r,c;
   inline bool operator < (const query &b) const {
      return r < b.r;
   }
}q[N];

int n,m;
ll f[N];
int main(){
   scanf("%d%d",&n,&m);
   fr(i,1,m){
      scanf("%d%d%d",&q[i].l,&q[i].r,&q[i].c);
   }
   sort(q+1,q+m+1);

   s.init();
   s.upd(n,0);
   fr(i,1,m){
      f[i] = q[i].c+s.query(n+1-q[i].l);
      s.upd(n+1-q[i].r,f[i]);
   }
   ll w = s.query(1);
   if(w == inf)puts("-1");
   else printf("%lld\n",w);
   return 0;
}
