#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  int n, m;
  cin >> n >> m;
  const long long INF = 1001001001;
  struct Edge {
    int to;
    long long cost;
  };
  vector<Edge> g[n];
  for (int i = 0; i < (n - 1); i++) {
    Edge edge = {i, 0};
    g[i + 1].push_back(edge);
  }
  for (int i = 0; i < (m); i++) {
    int l, r;
    cin >> l >> r;
    long long c;
    cin >> c;
    Edge edge1 = {r - 1, c};
    g[l - 1].push_back(edge1);
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  long long d[n];
  fill(d, d + n, INF);
  d[0] = 0;
  pq.push(pair<long long, int>(0, 0));
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (g[v].size()); i++) {
      auto e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        pq.push(pair<long long, int>(d[e.to], e.to));
      }
    }
  }
  long long ans = d[n - 1];
  if (ans >= INF) ans = -1;
  cout << ans << endl;
}
