#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct edge {
  int to;
  ll cost;
};
const ll INF = 1e18;
const int MAX_V = 1e5;
vector<edge> G[MAX_V];
vector<ll> d(MAX_V, INF);
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)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<int, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = n - 1; i >= 1; i--) G[i].push_back(edge{i - 1, 0});
  for (int i = 0; i < (int)m; i++) {
    int l, r;
    ll c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back(edge{r, c});
  }
  dijkstra(0);
  if (d[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << d[n - 1] << endl;
  return 0;
}
