#include <bits/stdc++.h>
using namespace std;
long long dd[330];
long long d[100100];
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = (0); i < (100100); ++i) d[i] = 1000000000000;
  for (long long i = (0); i < (330); ++i) dd[i] = 1000000000000;
  vector<pair<pair<long long, long long>, long long> > v;
  for (long long i = (0); i < (m); ++i) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    v.push_back(make_pair(make_pair(l, r), c));
  }
  sort((v).begin(), (v).end());
  d[0] = 0;
  for (long long i = (0); i < (m); ++i) {
    long long l1 = v[i].first.first;
    long long r1 = v[i].first.second;
    long long c1 = v[i].second;
    long long mn = 1000000000000;
    for (long long j = l1; j < r1 + 1;) {
      if (j % 330 == 0 && j + 330 <= r1) {
        mn = min(mn, dd[j / 330]);
        j += 330;
      } else {
        mn = min(mn, d[j]);
        j++;
      }
    }
    for (long long j = l1; j < r1 + 1;) {
      if (j % 330 == 0 && j + 330 <= r1) {
        dd[j / 330] = min(dd[j / 330], mn + c1);
        j += 330;
      } else {
        d[j] = min(d[j], mn + c1);
        dd[j / 330] = min(dd[j / 330], mn + c1);
        j++;
      }
    }
  }
  if (d[n - 1] == 1000000000000) {
    cout << -1 << "\n";
  } else {
    cout << d[n - 1] << "\n";
  }
  return 0;
}
