#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct edge {
  ll to, cost;
};
ll d[100005];
void dijkstra(int s, vector<vector<edge>> &G) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + 100005, 10000000000000);
  d[s] = 0;
  que.push({0, s});
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (auto n_v : G[v]) {
      if (d[n_v.to] > d[v] + n_v.cost) {
        d[n_v.to] = d[v] + n_v.cost;
        que.push({d[n_v.to], n_v.to});
      }
    }
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<edge>> G(N);
  for (int i = 1; i < N; i++) {
    G[i].push_back({i - 1, 0});
  }
  for (int i = 0; i < M; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back({r, c});
  }
  dijkstra(0, G);
  if (d[N - 1] == 10000000000000) d[N - 1] = -1;
  cout << d[N - 1] << endl;
}
