#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


#define P pair<ll, ll>
const int N_MAX = pow(10,5)+10;
struct edge { ll to; ll cost; };
vector<edge> adj[N_MAX], radj[N_MAX];

ll d[N_MAX];
ll N, M, T;

void dijkstra(ll s) {
  priority_queue<P, vector<P>, greater<P>> q;
  fill_n(d, N, LLINF); d[s] = 0; q.push(P(0, s));
  while (!q.empty()) {
    P p = q.top(); q.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;
    for (auto e: adj[v]) {
      if (d[e.to] > d[v]+e.cost) {
        d[e.to] = d[v]+e.cost;
        q.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  cin >> N >> M;
  rep(i,M) {
    int L, R, C; cin >> L >> R >> C; L--; R--;
    edge tmp = {R, C};
    adj[L].push_back(tmp);
  }
  rep(i,N-1) adj[i+1].push_back((edge){i, 0});
  dijkstra(0);
  int result = (d[N-1]!=0) ? d[N-1] : -1;
  // rep(i,N) cout << d[i] << " "; cout << endl;
  cout << result << endl;
  return 0;
}