#include <bits/stdc++.h>
using namespace std;
using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
constexpr LL INF = 1LL << 60;
template <typename T = pair<int, LL>>
void Dijkstra(int s, vector<vector<edge>> &g, vector<LL> &d) {
  int numv = d.size();
  priority_queue<T, vector<T>, greater<T>> q;
  for (int i = 0; i < numv; ++i) d[i] = INF;
  d[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    T p = q.top();
    q.pop();
    LL v = p.second;
    if (d[v] <= p.first) continue;
    for (int 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;
        q.emplace(d[e.to], e.to);
      }
    }
  }
}
void solve() {
  int n, m, l, r, c;
  cin >> n >> m;
  vector<vector<edge>> es(n);
  for (int i = int(0); i < int(m); i++) {
    cin >> l >> r >> c;
    --l;
    --r;
    es[l].emplace_back(r, c);
  }
  for (int i = int(1); i < int(n); i++) es[i].emplace_back(i - 1, 0);
  VLL d(n);
  Dijkstra(0, es, d);
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
}
int main() {
  solve();
  return 0;
}
