#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll,int> P;
const ll INF = 1e17;

vector<P> g[100005];

ll dist[100005];

int main() {
  int n,m;
  cin >> n >> m;

  for(int i = n - 1; i > 0; i--) {
    g[i].push_back(P(0,i-1));
  }
  

  for(int i = 0; i < m; i++) {
    int l,r,c;
    cin >> l >> r >> c;
    l--; r--;
    g[l].push_back(P(c,r));
  }

  for(int i = 0; i < n; i++) dist[i] = INF;

  priority_queue<P,vector<P>, greater<P> > q;

  dist[0] = 0;
  q.push(P(0,0));

  while(!q.empty()) {
    P v = q.top();
    q.pop();

    if(v.first > dist[v.second]) continue;

    for(int i = 0; i < g[v.second].size(); i++) {
      P u = g[v.second][i];
      if(dist[u.second] > dist[v.second] + u.first) {
	dist[u.second] = dist[v.second] + u.first;
	q.push(P(dist[u.second],u.second));
      }
    }
  }

  if(dist[n-1] == INF) cout << -1 << endl;
  else cout << dist[n-1] << endl;
}
    







    
