#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T& prov, const T& cur) {
  if (cur > prov) {
    prov = cur;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T& prov, const T& cur) {
  if (cur < prov) {
    prov = cur;
    return true;
  }
  return false;
}
ll ans = INT_MAX;
bool is_found = false;
int dst = -1;
void calc(const vector<vector<pair<int, int>>>& memo, int cur, ll cost) {
  if (ans <= cost) {
    return;
  }
  if (cur == dst) {
    ans = cost;
    is_found = true;
  }
  for (auto&& root : memo[cur]) {
    calc(memo, root.second, root.first + cost);
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  vector<int> C(M);
  vector<vector<pair<int, int>>> memo(N);
  for (int i = 0; i < M; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    L[i] = l - 1;
    R[i] = r - 1;
    C[i] = c;
    for (int k = L[i]; k < R[i]; k++) {
      memo[k].push_back(pair<int, int>(c, R[i]));
    }
  }
  dst = N - 1;
  calc(memo, 0, 0);
  if (is_found) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
