#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>

using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const ll INF = (ll)1e18;
const int MAXN = 100005;
vector<P> G[MAXN];
int n, m;

ll dijkstra(int start) {
  vector<ll> dist(n, INF);
  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > q;
  dist[start] = 0;
  q.emplace(0, start);
  while (!q.empty()) {
    pair<ll, int> cur = q.top(); q.pop();
    ll d = cur.first;
    int v = cur.second;
    if (dist[v] < d) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      P next = G[v][i];
      ll d2 = next.second + d;
      int u = next.first;
      if (d2 < dist[u]) {
	dist[u] = d2;
	q.emplace(d2, u);
      }
    }
  }
  return dist[n - 1];
}
int main() {
  cin >> n >> m;

  for (int i = 0; i < n - 1; ++i) G[i + 1].push_back(P(i, 0LL));
  for (int i = 0; i < m; ++i) {
    int l, r;
    ll c;
    cin >> l >> r >> c;
    l--; r--;
    G[l].push_back(P(r, c));
  }

  ll ans = dijkstra(0);
  if (ans == INF) puts("-1");
  else cout << ans << endl;
  return 0;
}
