#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long MOD = 1e9 + 7;
long long N, M;
struct Edge {
  long long to, cost;
};
vector<Edge> edgeList[100010];
long long d[100010];
int main() {
  cin >> N >> M;
  for (long long i = 0; i < M; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    edgeList[l].push_back(Edge{r, c});
  }
  for (long long i = 1; i < N; i++) {
    edgeList[i].push_back(Edge{i - 1, 0});
    d[i] = INF;
  }
  d[0] = 0;
  priority_queue<pair<long long, long long> > pq;
  pq.push(pair<long long, long long>(0, 0));
  while (!pq.empty()) {
    long long now = pq.top().second;
    long long nowC = pq.top().first;
    pq.pop();
    if (nowC > d[now]) continue;
    for (auto e : edgeList[now]) {
      long long newC = nowC + e.cost;
      if (d[e.to] > newC) {
        d[e.to] = newC;
        pq.push(pair<long long, long long>(newC, e.to));
      }
    }
  }
  cout << ((d[N - 1] == INF) ? (-1) : d[N - 1]);
  return 0;
}
