#include <bits/stdc++.h>

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  

double eps = .000000001;
const long long maxx = 1000000000000000000LL;
int main(){
  prep();
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > lr[n+1];
  for (int i=0; i<m; i++){
      int l, r, v;
      cin >> l >> r >> v;
      lr[l].push_back({r, v});
  }
  for (int i=1; i<=n-1; i++){
      lr[i+1].push_back({i, 0});
  }

  long long vals[n+1];
  bool got[n+1] = {false};
  got[1] = true;
  vals[1] = 0;
  queue<int> q;
  q.push(1);
  while (!q.empty()){
      int front = q.front();
      q.pop();
      for (int i=0; i<lr[front].size(); i++){
          int node = lr[front][i].first;
          long long val = lr[front][i].second;
          if (!got[node]){
              got[node] = true;
              vals[node] = val+vals[front];
              q.push(node);
          }else if (vals[node] > val+vals[front]){
              vals[node] = val+vals[front];
              q.push(node);
          }
      }
  }
  if (!got[n]){
      cout << -1;
  }else{
      cout << vals[n];
  }
  return 0; 
}