#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, ll>>> graph(N);
  for (int i = (int)(1); i < (int)(N); i++)
    graph.at(i).push_back(make_pair(i - 1, 0));
  for (int i = (int)(0); i < (int)(M); i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    graph.at(l).push_back(make_pair(r, c));
  }
  vector<ll> dist(N, 1e18);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      pq;
  dist.at(0) = 0;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    ll c = pq.top().first;
    int v = pq.top().second;
    pq.pop();
    for (int i = (int)(0); i < (int)(((int)(graph.at(v)).size())); i++) {
      int nv = graph.at(v).at(i).first;
      int nc = c + graph.at(v).at(i).second;
      if (dist.at(nv) <= nc) continue;
      dist.at(nv) = nc;
      pq.push(make_pair(nc, nv));
    }
  }
  ll ans = dist.at(N - 1);
  if (ans == 1e18) ans = -1;
  cout << ans << endl;
  return 0;
}
