#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, m; cin >> n >> m;
  vector<vector<pair<int, int>>> adj(n);
  for (int i = 0; i < m; ++i) {
    int a, b, c; cin >> a >> b >> c; --a, --b;
    adj[a].emplace_back(b, c);
  }
  for (int i = 0; i < n - 1; ++i) {
    adj[i + 1].emplace_back(i, 0);
  }
  const long long INF = (long long)1e18L;
  vector<long long> dist(n, INF);
  priority_queue<pair<long long, int>, 
    vector<pair<long long, int>>,
      greater<pair<long long, int>>> pq;
  pq.emplace(0, 0);
  dist[0] = 0;
  while (!pq.empty()) {
    int node; long long cost; tie(cost, node) = pq.top(); pq.pop();
    if (dist[node] < cost) continue;
    if (node == n - 1) {
      cout << cost << endl;
      return 0;
    }
    for (auto &p : adj[node]) {
      int x, c; tie(x, c) = p;
      if (cost + c < dist[x]) {
        dist[x] = cost + c;
        pq.emplace(dist[x], x);
      }
    }
  }
  cout << "-1\n";

  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}