#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, vector<pair<int, int>>> um;
  vector<int> v(n, numeric_limits<int>::max());
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    for (int j = l; j < r; ++j) {
      v[j] = min(v[j], c);
    }
    um[r].push_back({l, c});
  }
  for (int i = 1; i < n; ++i) {
    if (v[i] == numeric_limits<int>::max()) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> answer(n, 0);
  int i = 0;
  while (v[i] == v[0]) answer[i] = v[i++];
  for (; i < n; ++i) {
    answer[i] = answer[i - 1] + v[i];
    for (auto p : um[i + 1]) {
      answer[i] = min(answer[i], answer[p.first - 1] + p.second);
      for (int j = i; j >= p.first - 1; --j) {
        answer[j] = min(answer[j], answer[i]);
      }
    }
  }
  cout << answer.back() << endl;
}
