#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
struct Range {
  long long l, r, cost, sum;
};
bool operator<(const Range& a, const Range& b) {
  return (a.l != b.l) ? a.l < b.l : a.r <= b.r;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<Range> CLR(m + 2);
  for (int i = 0; i < m; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    CLR[i] = {a, b, c, (long long)1e14};
  }
  CLR[m] = {1, 1, 0, 0};
  CLR[m + 1] = {n, n, 0, (long long)1e14};
  sort(CLR.begin(), CLR.end());
  for (int i = 0; i < m + 2; i++) {
    for (int j = i + 1; j < m + 2; j++) {
      if (CLR[i].r < CLR[j].l) break;
      if (CLR[i].r > CLR[j].r) continue;
      CLR[j].sum = min(CLR[j].sum, CLR[i].sum + CLR[j].cost);
    }
  }
  if (CLR[m + 1].sum == (long long)1e14)
    cout << -1 << endl;
  else
    cout << CLR[m + 1].sum << endl;
}
