#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> graph[n+1];
  for (int i = 2; i <= n; i++) {
    graph[i].emplace_back(i-1, 0);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    graph[l].emplace_back(r, c);
  }

  int d[n+1];
  for (int i = 1; i <= n; i++) d[i] = INT_MAX;

  priority_queue<pair<int, int>> pq;
  pq.emplace(0, 1);

  while (!pq.empty()) {
    int w = -pq.top().first;
    int v = pq.top().second;
    pq.pop();
    if (d[v] == INT_MAX) {
      d[v] = w;
      for (auto child : graph[v]) {
        if (d[child.first] == INT_MAX) {
          pq.emplace(-w - child.second, child.first);
        }
      }
    }
  }

  if (d[n] == INT_MAX) cout << -1;
  else cout << d[n];
}