#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int to;
  int cost;
} edge;
typedef struct {
  long dist;
  int v;
} rte;
bool operator<(const rte a, const rte b) { return a.dist > b.dist; }
vector<edge> G[100000];
long d[100000];
void dijkstra(int s, int t);
int main() {
  int N, M;
  cin >> N >> M;
  int L[M], R[M], C[M];
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i] >> C[i];
    L[i]--;
    R[i]--;
  }
  bool bonded[N];
  for (int i = 0; i < N; i++) bonded[i] = false;
  for (int i = 0; i < M; i++) {
    G[L[i]].emplace_back(edge{R[i], C[i]});
    for (int j = L[i]; j < R[i]; j++) {
      if (!bonded[j]) {
        G[j + 1].emplace_back(edge{j, 0});
        bonded[j] = true;
      }
    }
  }
  dijkstra(0, N);
  if (d[N - 1] == 1e15)
    cout << -1 << endl;
  else
    cout << d[N - 1] << endl;
  return 0;
}
void dijkstra(int s, int V) {
  for (int i = 0; i < V; i++) d[i] = 1e15;
  priority_queue<rte> que;
  d[s] = 0;
  que.push(rte{d[s], s});
  for (;;) {
    if (que.empty()) return;
    rte now = que.top();
    que.pop();
    for (edge e : G[now.v]) {
      if (d[e.to] > d[now.v] + e.cost) {
        d[e.to] = d[now.v] + e.cost;
        que.push(rte{d[e.to], e.to});
      }
    }
  }
}
