#include <bits/stdc++.h>
using namespace std;
long long d_1[100001];
pair<pair<int, int>, int> LRC[100000];
int main() {
  int N, M, L, R, C, preL = 0;
  int determined = 1, pdet = 1;
  cin >> N >> M;
  for (int i = 0; i < (N); i++) d_1[i] = (10000000000);
  d_1[1] = 0;
  for (int i = 0; i < (M); i++) {
    cin >> L >> R >> C;
    LRC[i] = make_pair(make_pair(L, C), R);
  }
  sort(LRC, LRC + M);
  for (int i = 0; i < (M); i++) {
    L = LRC[i].first.first;
    C = LRC[i].first.second;
    R = LRC[i].second;
    if (preL != L) pdet = L;
    if (L == 1) {
      for (int j = (determined + 1); j <= (R); j++) {
        d_1[j] = (long long)C;
      }
      determined = R;
      continue;
    }
    if (L > determined || (i == 1 && L != 1)) {
      cout << -1 << endl;
      return 0;
    }
    if (R <= determined) {
      if (d_1[L] + (long long)C < d_1[R]) {
        for (int j = (pdet + 1); j <= (R); j++) d_1[j] = d_1[L] + (long long)C;
        pdet = R;
      }
    } else {
      if (d_1[L] + (long long)C < d_1[determined]) {
        for (int j = (pdet + 1); j <= (R); j++) d_1[j] = d_1[L] + (long long)C;
      }
      for (int j = (determined + 1); j <= (R); j++)
        d_1[j] = d_1[L] + (long long)C;
      determined = R;
      pdet = determined;
    }
    preL = L;
  }
  if (determined == N)
    cout << d_1[N] << endl;
  else
    cout << -1 << endl;
  return 0;
}
