#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long mod2 = 998244353;
const long long INF = (long long)1000000000 * (long long)100005;
const long double EPS = 1e-10;
const int MAX = 100005;
struct Edge {
  int to;
  long long cost;
  Edge(int to, long long cost) : to(to), cost(cost) {}
  bool operator<(const Edge e) const { return cost < e.cost; }
};
vector<Edge> G[MAX];
long long d[MAX];
int n;
void dijkstra() {
  for (int i = 0; i < (n); ++i) d[i] = INF;
  d[0] = 0;
  int u;
  priority_queue<Edge> pq;
  pq.push(Edge(0, 0));
  while (!pq.empty()) {
    Edge ee = pq.top();
    pq.pop();
    u = ee.to;
    if (d[u] < -ee.cost) continue;
    for (Edge e : G[u]) {
      if (d[u] + e.cost < d[e.to]) {
        d[e.to] = d[u] + e.cost;
        e.cost *= -1;
        pq.push(e);
      }
    }
  }
}
int main() {
  int m, l, r, c;
  cin >> n >> m;
  for (int i = 0; i < (n - 1); ++i) {
    G[i + 1].push_back(Edge(i, 0));
  }
  for (int i = 0; i < (m); ++i) {
    cin >> l >> r >> c;
    G[l - 1].push_back(Edge(r - 1, c));
  }
  dijkstra();
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
  return 0;
}
