#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  const long long inf = 1ll << 62;
  multimap<int, tuple<int, int, long long>> e;
  for (decltype(m) i = (0); i < (m); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    e.emplace(l, make_tuple(r, c, inf));
  }
  e.emplace(n, make_tuple(n, 0, inf));
  for (auto& i : e) {
    if (i.first != 1) break;
    get<2>(i.second) = 0;
  }
  for (auto& i : e) {
    if (get<2>(i.second) == inf) continue;
    const long long next = get<2>(i.second) + get<1>(i.second);
    for (auto it = e.lower_bound(i.first + 1),
              end = e.lower_bound(get<0>(i.second) + 1);
         it != end; ++it)
      if (get<2>(it->second) > next) get<2>(it->second) = next;
  }
  const auto res = get<2>(e.rbegin()->second);
  cout << (res == inf ? -1 : res) << endl;
  return 0;
}
