#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
const long long MAX_COST = 10000000000;
const long long INF = MAX_N * MAX_COST;
struct Edge {
  int l;
  int r;
  int c;
  Edge(int l = -1, int r = -1, int c = -1) {
    this->l = l;
    this->r = r;
    this->c = c;
  }
  bool operator>(const Edge &e) const {
    return l * MAX_COST + c > e.l * MAX_COST + e.c;
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<Edge, vector<Edge>, greater<Edge>> pque;
  int l, r, c;
  for (int i = 0; i < M; ++i) {
    cin >> l >> r >> c;
    pque.push(Edge(l, r, c));
  }
  long long dist[N + 10];
  for (int i = 0; i <= N; ++i) {
    dist[i] = INF;
  }
  dist[1] = 0;
  while (!pque.empty()) {
    Edge edge = pque.top();
    pque.pop();
    long long cost = dist[edge.l] + edge.c;
    if (dist[r] > cost) {
      for (int j = edge.l; j <= edge.r; ++j) {
        dist[j] = min(dist[j], cost);
      }
    }
  }
  if (dist[N] == INF) {
    cout << -1 << endl;
  } else {
    cout << dist[N] << endl;
  }
  return 0;
}
