#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int inf = 1e9 + 10;
const long long INF = 1e18;
const long double EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct Edge {
  long long t, c;
  bool operator<(const Edge &e) const { return c != e.c ? c > e.c : t > e.t; }
};
vector<Edge> G[100100];
vector<long long> d(100100, INF);
vector<bool> visited(100100, false);
void dijkstra() {
  d[0] = 0;
  priority_queue<Edge> pq;
  pq.push({0, 0});
  while (!pq.empty()) {
    int v = pq.top().t, dist = pq.top().c;
    pq.pop();
    if (d[v] < dist) continue;
    for (Edge e : G[v]) {
      long long u = e.t, c = e.c;
      if (d[u] > d[v] + c) {
        d[u] = d[v] + c;
        pq.push(e);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (n - 1); ++i) G[i + 1].push_back({i, 0});
  for (int i = 0; i < (m); ++i) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].push_back({r, c});
  }
  dijkstra();
  cout << (d[n - 1] == INF ? -1 : d[n - 1]) << '\n';
  return 0;
}
