#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);
  }
  while (m--) {
    int l, r, c;
    cin >> l >> r >> c;
    graph[l].emplace_back(r, c);
  }
  priority_queue<pair<int,int>> pq;
  pq.emplace(0, 1);
  vector<int> dist(n+1, INT_MAX);
  while (!pq.empty()) {
    pair<int,int> cur = pq.top();
    pq.pop();
    int v = cur.second;
    int w = -cur.first;
    if (dist[v] == INT_MAX) {
      dist[v] = w;
      for (pair<int,int> child : graph[v]) {
        if (dist[child.first] == INT_MAX) {
          pq.emplace(-w - child.second, child.first);
        }
      }
    }
  }
  if (dist[n] == INT_MAX) {
    cout << -1;
    return 0;
  }
  cout << dist[n];
}