#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct edge {
  int to;
  long long co;
  edge(int t, long long c) : to(t), co(c) {}
  bool operator<(const edge e) const { return co > e.co; }
};
int N, M;
vector<edge> G[100005];
long long cost[100005];
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].emplace_back(r, c);
  }
  for (int i = 0; i < N - 1; i++) {
    G[i + 1].emplace_back(i, 0);
  }
  for (int i = 0; i < N; i++) cost[i] = INF;
  cost[0] = 0;
  priority_queue<edge> pq;
  pq.emplace(0, 0);
  while (!pq.empty()) {
    edge now = pq.top();
    pq.pop();
    if (cost[now.to] != INF) continue;
    for (auto e : G[now.to]) {
      if (cost[e.to] > cost[now.to] + e.co) {
        cost[e.to] = cost[now.to] + e.co;
        pq.emplace(e.to, e.co);
      }
    }
  }
  if (cost[N - 1] == INF)
    cout << -1 << endl;
  else
    cout << cost[N - 1] << endl;
  return 0;
}
