#include <bits/stdc++.h>
using namespace std;
const int MAX = 100100;
const long long INF = 1001001001001;
struct edge {
  int to, cost;
};
int v;
vector<vector<edge>> G(MAX);
long long d[MAX];
void dijkstra(int s) {
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      pq;
  for (int i = 0; i < (v); i++) d[i] = INF;
  d[s] = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    pair<long long, int> p = pq.top();
    pq.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (edge u : G[v]) {
      if (d[u.to] > d[v] + u.cost) {
        d[u.to] = (long long)d[v] + u.cost;
        pq.push({d[u.to], u.to});
      }
    }
  }
}
int main() {
  cin >> v;
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back({r, c});
  }
  for (int i = 0; i < (v); i++)
    if (i + 1 < n) G[i + 1].push_back({i, 0});
  dijkstra(0);
  if (d[v - 1] < INF)
    cout << d[v - 1];
  else
    cout << -1;
}
