#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  set<tuple<int, long long, int> > edgeSet;
  for (int i = 0; i < M; i++) {
    int L, R;
    long long C;
    cin >> L >> R >> C;
    edgeSet.insert(tuple<int, long long, int>(L, C, R));
  }
  auto ite = edgeSet.begin();
  long long INF = 10e9 + 1;
  vector<long long> dp(N + 1, INF);
  dp.at(1) = 0;
  while (ite != edgeSet.end()) {
    tuple<int, long long, int> edge = *ite;
    int left = get<0>(edge);
    long long cost = get<1>(edge);
    int right = get<2>(edge);
    if (dp.at(left) == INF) {
      ite++;
      continue;
    }
    long long currentDistance = cost + dp.at(left);
    for (int i = right; i >= left; i--) {
      if (dp.at(i) <= currentDistance) {
        break;
      }
      dp.at(i) = currentDistance;
    }
    ite++;
  }
  if (dp.at(N) == INF) {
    cout << -1 << endl;
  } else {
    cout << dp.at(N) << endl;
  }
  return 0;
}
