#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<long long, pair<long long, long long>>> V;
  long long A, B, C;
  for (long long i = 0; i < M; ++i) {
    cin >> A >> B >> C;
    --A;
    --B;
    V.push_back({A, {C, B}});
  }
  sort(V.begin(), V.end());
  long long dp[N];
  for (long long i = 0; i < N; ++i) dp[i] = INF;
  dp[0] = 0;
  if (V[0].first != 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = V[0].first + 1; i < V[0].second.second + 1; ++i)
    dp[i] = V[0].second.first;
  for (long long i = 1; i < M; ++i) {
    if (V[i].first == V[i - 1].first) {
      for (long long j = V[i - 1].second.second + 1; j < V[i].second.second + 1;
           ++j) {
        long long A = V[i].first, B = V[i].second.first;
        dp[j] = min(dp[j], B);
      }
    } else {
      for (long long j = V[i].first + 1; j < V[i].second.second + 1; ++j) {
        int A = V[i].first, B = V[i].second.first;
        dp[j] = min(dp[j], dp[A] + B);
      }
    }
  }
  if (dp[N - 1] != INF)
    cout << dp[N - 1] << endl;
  else
    cout << -1 << endl;
}
