#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

struct edge{int to; ll cost;};
typedef pair<ll, int> P;
const ll INF = 1e18;
const int MAX_V = 1e5;

vector<edge> G[MAX_V];
vector<ll> d(MAX_V,INF); 

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  for(int i = n-1; i >= 1; i--) G[i].push_back(edge{i-1,0});
  rep(i,m) {
    int l, r; ll c;
    cin >> l >> r >> c;
    l--; r--;
    G[l].push_back(edge{r,c});
  }
  dijkstra(0);
  if(d[n-1] == INF) cout << -1 << endl;
  else cout << d[n-1] << endl;
  return 0;
}