#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
const long long MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, long long>> LRC(M);
  int l, r;
  long long c;
  for (int i = 0; i < (M); ++i) {
    cin >> l >> r >> c;
    --l, --r;
    LRC[i] = forward_as_tuple(l, r, c);
  }
  sort((LRC).begin(), (LRC).end());
  vector<long long> dp(N, LINF);
  dp[0] = 0;
  for (int i = 0; i < (M); ++i) {
    tie(l, r, c) = LRC[i];
    if (dp[l] == LINF) continue;
    for (int j = l + 1; j <= r; j++) {
      dp[j] = min(dp[j], dp[l] + c);
    }
  }
  if (dp[N - 1] == LINF)
    cout << -1 << endl;
  else
    cout << dp[N - 1] << endl;
  return 0;
}
