#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
vector<pair<int, int>> adj[100001];
long long int dist[100001];
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, l, r, c;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> c;
    adj[l].push_back(make_pair(r, c));
  }
  for (int i = 2; i <= n; i++) {
    adj[i].push_back(make_pair(i - 1, 0));
  }
  if (adj[1].size() == 0) {
    cout << -1 << '\n';
    return 0;
  }
  fill(dist, dist + 100001, INF);
  dist[1] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pque;
  pque.push(make_pair(dist[1], 1));
  while (!pque.empty()) {
    int now = pque.top().second;
    if (dist[now] < pque.top().first) {
      pque.pop();
      continue;
    }
    pque.pop();
    for (auto it : adj[now]) {
      int cost = it.second;
      int next = it.first;
      if (dist[next] > dist[now] + cost) {
        dist[next] = dist[now] + cost;
        pque.push(make_pair(dist[next], next));
      }
    }
  }
  if (dist[n] == INF) {
    cout << -1 << '\n';
  } else {
    cout << dist[n] << '\n';
  }
  return 0;
}
