#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr int MOD = 998244353;
ll N, M, L, R, C;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<tuple<ll, ll, ll>> query;
  for (int i = 0; i < M; ++i) {
    cin >> L >> R >> C;
    --L, --R;
    query.emplace_back(L, R, C);
  }
  sort(query.begin(), query.end());
  vector<ll> dp(N + 1, INF);
  dp[0] = 0;
  for (int i = 0; i < M; ++i) {
    ll l, r, c;
    tie(l, r, c) = query[i];
    for (int j = l; j < r; ++j) {
      for (int k = j + 1; k <= r; ++k) {
        dp[k] = min(dp[k], dp[j] + c);
      }
    }
  }
  if (dp[N - 1] == INF)
    cout << -1;
  else
    cout << dp[N - 1] << endl;
  return 0;
}
