#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;
struct edge {
  ll to, cost;
  edge(ll a, ll b) {
    to = a;
    cost = b;
  }
};
using P = pair<ll, ll>;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<edge>> g(n);
  for (ll i = (0); i < (m); i++) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    g[l].push_back(edge(r, c));
    for (ll j = (l + 1); j < (r + 1); j++) {
      g[j].push_back(edge(j - 1, 0));
    }
  }
  ll d[n];
  fill(d, d + n, mod);
  priority_queue<P, vector<P>, greater<P>> q;
  d[0] = 0;
  q.push(P(0, 0));
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;
    for (ll i = (0); i < (g[v].size()); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push(P(d[e.to], e.to));
      }
    }
  }
  if (d[n - 1] == mod) {
    cout << -1 << endl;
    return 0;
  }
  cout << d[n - 1] << endl;
  return 0;
}
