#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<ll, int>>> cost(N);
  for (int i = 1; i < N; i++) {
    cost[i].push_back(make_pair(0, i - 1));
  }
  for (int i = 0; i < M; i++) {
    int L, R, C;
    cin >> L >> R >> C;
    L--, R--;
    cost[L].push_back(make_pair(C, R));
  }

  vector<ll> to(N);
  for (int i = 1; i < N; i++) to[i] = 1e15;
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    int c = que.top().first, now = que.top().second;
    que.pop();
    if (c > to[now]) continue;
    for (int i = 0; i < cost[now].size(); i++) {
      if (to[cost[now][i].second] > to[now] + cost[now][i].first) {
        to[cost[now][i].second] = to[now] + cost[now][i].first;
        que.push(make_pair(to[cost[now][i].second], cost[now][i].second));
      }
    }
  }
  cout << (to[N - 1] == 1e15 ? -1 : to[N - 1]) << endl;
}