#include <bits/stdc++.h>
using namespace std;
long long INF = 1e6;
long long n = INF, m;
vector<vector<pair<int, int>>> graph(n, vector<pair<int, int>>(0));
int dijkstra(int goal) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  pq.push(make_pair(0, 0));
  vector<int> visited(n, 0);
  while (!pq.empty()) {
    auto now = pq.top();
    pq.pop();
    int cost, node;
    tie(cost, node) = now;
    if (node == goal) {
      return cost;
    }
    if (visited.at(node) == 1) {
      continue;
    } else {
      visited.at(node) = 1;
      for (auto next : graph.at(node)) {
        int next_cost, next_node;
        tie(next_cost, next_node) = next;
        pq.push(make_pair(cost + next_cost, next_node));
      }
    }
  }
  return -1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    graph.at(i).push_back(make_pair(0, i - 1));
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    graph.at(l - 1).push_back(make_pair(c, r - 1));
  }
  cout << dijkstra(n - 1) << endl;
}
