#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pll = pair<long, long>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define INF 1e18

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<pll>> Graph(n);
  rep(i,n-1){
    Graph.at(i+1).push_back(pll(i,0));
  }
  rep(i,m){
    long l,r,c;
    cin >> l >> r >> c;
    Graph.at(l-1).push_back(pll(r-1,c));
  }
  priotiry_queue<pll> que;
  vector<long> dis(n,INF);
  dis.at(0) = 0;
  que.push(pll(0,0));
  while(que.size()){
    pll P = que.top();
    que.pop();
    long v = P.first;
    long d = P.second;
    //cout << v << endl;
    if(d > dis.at(v)) continue;
    //cout << d << " " << dis.at(v) << endl;
    for(pll nP : Graph.at(v)){
      long nv = nP.first;
      long cost = nP.second;
      if(d + cost < dis.at(nv)){
        dis.at(nv) = d + cost;
        que.push(pll(nv,dis.at(nv)));
      }
    }
  }
  //rep(i,n-1) cout << dis.at(i) << endl;
  if(dis.at(n-1) == INF) cout << -1 << endl;
  else cout << dis.at(n-1) << endl;
}
