#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 40;
const ll MOD = 1000000007;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> info[N];
  for (ll i = 0; i < M; i++) {
    ll L, R, C;
    cin >> L >> R >> C;
    L--;
    R--;
    info[L].push_back(make_pair(R, C));
  }
  for (ll i = 0; i < N - 1; i++) info[i + 1].push_back(make_pair(i, 0));
  ll sum[N];
  for (ll i = 0; i < N; i++) {
    if (!i)
      sum[i] = 0;
    else
      sum[i] = INF;
  }
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  que.push(make_pair(0, 0));
  while (que.size()) {
    ll d = que.top().first, v = que.top().second;
    que.pop();
    for (auto i : info[v]) {
      ll nv = i.first;
      ll nc = i.second;
      if (d + nc < sum[nv]) {
        sum[nv] = d + nc;
        que.push(make_pair(sum[nv], nv));
      }
    }
  }
  if (sum[N - 1] == INF)
    cout << -1 << endl;
  else
    cout << sum[N - 1] << endl;
  return 0;
}
