#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433;
int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  ;
  int m;
  cin >> m;
  ;
  vector<int> l(m), r(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
  }
  vector<int> id(m);
  iota(id.begin(), id.end(), 0);
  sort(id.begin(), id.end(), [&](int i1, int i2) {
    if (l[i1] == l[i2])
      return r[i1] < r[i2];
    else
      return l[i1] < l[i2];
  });
  const int INF = 1e9;
  vector<int> dp(n + 1, INF);
  dp[0] = dp[1] = 0;
  int prevL = 1;
  int prevR = 1;
  for (int i = 0; i < m; i++) {
    for (int j = max(l[id[i]], prevR); j <= r[id[i]]; j++) {
      dp[j] = min(dp[j], dp[l[id[i]]] + c[id[i]]);
    }
    prevR = r[id[i]];
  }
  if (dp[n] == INF)
    cout << -1 << endl;
  else
    cout << dp[n] << endl;
}
