#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  for (int i = (int)(0); i < (int)(v.size()); i++) {
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}
const long long INF = 1e18 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> G(N + 1);
  vector<long long> D(N + 1, INF);
  for (int i = (int)(0); i < (int)(M); i++) {
    int l, r, c;
    cin >> l >> r >> c;
    G[l].push_back(pair<int, int>(r, c));
  }
  for (int i = (int)(1); i < (int)(N); i++) {
    G[i + 1].push_back(pair<int, int>(i, 0));
  }
  D[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  que.push(pair<int, int>(0, 1));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    if (p.second == N) {
      break;
    }
    if (p.first > D[p.second]) {
      continue;
    }
    for (const auto &w : G[p.second]) {
      if (D[w.first] > D[p.second] + w.second) {
        D[w.first] = D[p.second] + w.second;
        que.push(pair<int, int>(D[w.first], w.first));
      }
    }
  }
  if (D[N] < INF) {
    cout << D[N] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
