#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 100000000000;
int main() {
  ll N, M;
  cin >> N >> M;
  vll L(N), R(N), C(N);
  for (ll i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> C[i];
  }
  vector<vector<P>> e(N, vector<P>(0));
  for (ll i = 0; i < M; i++) {
    P v = make_pair(R[i] - 1, C[i]);
    e[L[i] - 1].emplace_back(v);
  }
  for (ll i = N - 1; i > 0; i--) {
    P v = make_pair(i - 1, 0);
    e[i].emplace_back(v);
  }
  priority_queue<P, vector<P>, greater<P>> pq;
  vector<ll> d(N, INF);
  d[0] = 0;
  pq.emplace(P(0, 0));
  while (!pq.empty()) {
    P x = pq.top();
    pq.pop();
    ll &y = x.first;
    ll &z = x.second;
    if (y > d[z]) continue;
    for (auto p : e[z]) {
      if (d[p.first] > d[z] + p.second) {
        d[p.first] = d[z] + p.second;
        pq.emplace(P(d[p.first], p.first));
      }
    }
  }
  if (d[N - 1] == INF) {
    cout << (-1);
  } else {
    cout << (d[N - 1]);
  }
}
