#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
void Main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, pair<int, ll>>> items;
  for (ll i = 0; i < (ll)(M); i++) {
    int l, r;
    ll c;
    cin >> l >> r >> c;
    items.push_back({r, {l, c}});
  }
  sort(items.begin(), items.end());
  vector<ll> dp(N, INF);
  dp[0] = 0;
  for (ll i = 0; i < (ll)(M); i++) {
    int r = items[i].first;
    int l = items[i].second.first;
    ll c = items[i].second.second;
    l--;
    r--;
    int k = -1;
    ll x = INF;
    for (ll j = l; j < (ll)(r + 1); j++) {
      if (dp[j] < x) {
        x = dp[j];
        k = j;
      }
    }
    dp[r] = min(dp[r], x + c);
  }
  if (dp[N - 1] != INF) {
    cout << dp[N - 1] << '\n';
  } else {
    cout << -1 << '\n';
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
