#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,m;
  cin >> n >> m;
  vector<int> l(m),r(m),c(m);
  REP(i,m) cin >> l[i] >> r[i] >> c[i];
  vector<vector<pair<int,int>>> nei(n+1);
  REP(i,m) {
    nei[l[i]].emplace_back(r[i], c[i]);
  }
  FOR(i,1,n) {
    nei[i+1].emplace_back(i,0);
  }

  priority_queue<pair<LL,LL>> q;
  set<LL> already;
  // negc, pos
  q.emplace(0,1);
  while(!q.empty()) {
    LL negc,pos;
    tie(negc,pos) = q.top();
    q.pop();
    if(!already.insert(pos).second) continue;
    if(pos == n) {
      cout << -negc << endl;
      return 0;
    }
    for(auto pa:nei[pos]) {
      q.emplace(negc - pa.second, pa.first);
    }
  }
  cout << -1 << endl;
  return 0;
}
