#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const long long INF = 1e10;
const int MOD = 1e9 + 7;
struct edge {
  int to, cost;
};
vector<edge> G[MAX];
long long d[MAX];
int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < (M); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    edge e = edge();
    e.to = r, e.cost = c;
    G[l].push_back(e);
  }
  for (int i = 1; i < N; ++i) {
    edge e = edge();
    e.to = i - 1, e.cost = 0;
    G[i].push_back(e);
  }
  for (int i = 0; i < (N); ++i) {
    d[i] = INF;
  }
  d[0] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      que;
  que.push(pair<int, int>(0, 0));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (auto e : G[v]) {
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<int, int>(d[e.to], e.to));
      }
    }
  }
  if (d[N - 1] != INF) {
    cout << d[N - 1] << endl;
  } else {
    cout << -1 << endl;
  }
}
