#include <bits/stdc++.h>
using namespace std;
int main() {
  const long inf = 1l << 60;
  int n, m;
  cin >> n >> m;
  vector<vector<long>> c(m, vector<long>(3));
  for (int i = 0; i < m; i++)
    for (int j = 0; j < 3; j++) cin >> c.at(i).at(j);
  sort(c.begin(), c.end());
  vector<long> dp(n + 1, inf);
  dp.at(1) = 0;
  for (int i = 0; i < m; i++) {
    long prev = dp.at(c.at(i).at(0));
    for (long j = c.at(i).at(0) + 1; j <= c.at(i).at(1); j++) {
      dp.at(j) = min(dp.at(j), prev + c.at(i).at(2));
    }
  }
  if (dp.at(n) == inf) {
    cout << -1 << endl;
  } else {
    cout << dp.at(n) << endl;
  }
}
