#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;
using ll = long long;
int main() {
  uint N, M;
  cin >> N >> M;
  vector<pair<pair<uint, uint>, uint>> LRC(M);
  uint l, r, c;
  for (uint i = 0; i < M; i++) {
    cin >> l >> r >> c;
    auto p = make_pair(l - 1, r - 1);
    LRC[i] = make_pair(p, c);
  }
  sort(LRC.begin(), LRC.end());
  vector<ll> d(N, -1);
  d[0] = 0;
  for (uint i = 0; i < M; i++) {
    auto LR = LRC[i].first;
    uint L = LR.first;
    uint R = LR.second;
    uint C = LRC[i].second;
    if (d[L] == -1) {
      cout << -1;
      return 0;
    }
    for (uint j = L + 1; j <= R; j++) {
      d[j] = (d[j] == -1) ? d[L] + C : min(d[j], d[L] + C);
    }
  }
  cout << d[N - 1];
  return 0;
}
