#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to;
  int cost;
};
const long long INF = 1e9 + 1;
const long long LINF = 1e18 + 1;
const long long MOD = 1e9 + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
const int MAX_N = 1e5;
vector<vector<Edge> > tree;
long long dist[MAX_N] = {};
int main(void) {
  int n, m;
  cin >> n >> m;
  tree.resize(n);
  fill_n(dist, n, LINF);
  for (int(i) = (1); (i) <= (n - 1); (i)++) {
    Edge e = {i - 1, 0};
    tree[i].push_back(e);
  }
  for (int(i) = (0); (i) < (m); (i)++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    Edge e = {r, c};
    tree[l].push_back(e);
  }
  priority_queue<pair<long long, long long> > q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    pair<long long, long long> p = q.top();
    q.pop();
    if (p.first >= dist[p.second]) continue;
    dist[p.second] = p.first;
    for (int(i) = (0); (i) < (tree[p.second].size()); (i)++) {
      Edge e = tree[p.second][i];
      q.push(make_pair(p.first + e.cost, e.to));
    }
  }
  if (dist[n - 1] == LINF)
    cout << (-1) << endl;
  else
    cout << (dist[n - 1]) << endl;
  return 0;
}
