#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> p;
  int l, r, c;
  for (int i = 0; i < (m); i++) {
    cin >> l >> r >> c;
    l--;
    r--;
    p.emplace_back(l, r, c);
  }
  sort((p).begin(), (p).end());
  vector<long long> ans(n, INT64_MAX);
  ans[0] = 0;
  for (int i = 0; i < (m); i++) {
    for (int j = (get<0>(p[i])); j < (get<1>(p[i])); j++) {
      for (int k = (j + 1); k < (get<1>(p[i]) + 1); k++) {
        if (ans[j] != INT64_MAX) ans[k] = min(ans[k], ans[j] + get<2>(p[i]));
        ;
      }
    }
  }
  if (ans.back() == INT64_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans.back() << endl;
  }
  return 0;
}
