#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
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;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  vector<pair<pair<long long, long long>, long long>> p(n);
  for (long long(i) = 0; (i) < (m); (i)++) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    p[i] = make_pair(make_pair(r, l), c);
  }
  sort(p.begin(), p.end(),
       greater<pair<pair<long long, long long>, long long>>());
  bool update = 0;
  vector<long long> dp(114514, INF);
  dp[n - 1] = 0;
  long long x = 0;
  for (long long(i) = ((n)-1); (i) >= 0; (i)--) {
    for (long long j = x; j < n; j++) {
      if (p[j].first.first < i) break;
      if (p[j].first.second < i) x = j;
      chmin(dp[p[j].first.second], dp[i] + p[j].second);
    }
  }
  if (dp[0] == INF)
    cout << -1 << endl;
  else
    cout << dp[0] << endl;
}
