#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> L;
  for (int i = 0; i < M; ++i) {
    long long a, b, c;
    cin >> a >> b >> c;
    L.emplace_back(a, b, c);
  }
  sort((L).begin(), (L).end());
  long long DP[200000];
  for (int i = (0); i < (200000); ++i) DP[i] = ((1LL << 62) - (1LL << 31));
  for (int i = 0; i < M; ++i) {
    for (int j = get<0>(L[i]) + 1; j <= get<1>(L[i]); ++j) {
      DP[j] = min(DP[j], DP[get<0>(L[i])] + get<2>(L[i]));
    }
  }
  if (DP[N] == 0)
    cout << -1 << endl;
  else
    cout << DP[N] << endl;
}
