#include <bits/stdc++.h>
using namespace std;
const long long INF = (1 << 30) - 1;
const long long LLINF = (1LL << 60LL);
const long long MOD = 1000000007;
const long long mod = 998244353;
const long long MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct edge {
  long long to, cost;
};
long long n;
vector<edge> G[100010];
long long d[100010];
void dijkstra(int s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  fill(d, d + n + 1, LLINF);
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (long long i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<long long, long long>(d[e.to], e.to));
      }
    }
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long m;
  pair<pair<long long, long long>, long long> s[100010];
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    G[l].push_back({r, c});
  }
  for (long long i = 2; i < n + 1; i++) {
    G[i].push_back({i - 1, 0});
  }
  dijkstra(1);
  if (d[n] == LLINF) {
    cout << -1 << endl;
  } else
    cout << d[n] << endl;
  return 0;
}
