#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long from, to, weight;
};
vector<long long> dijkstra(vector<struct Edge> &edges, long long num_vertex,
                           long long start_vertex) {
  vector<long long> distances(num_vertex, LONG_LONG_MAX);
  distances[start_vertex] = 0;
  vector<bool> is_used(num_vertex, false);
  vector<vector<struct Edge>> from_edges(num_vertex);
  for (struct Edge e : edges) {
    from_edges[e.from].push_back(e);
  }
  auto compare = [](pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
  };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(compare)> q(
      compare);
  q.push(make_pair(start_vertex, 0));
  while (!q.empty()) {
    pair<int, int> from_and_cost = q.top();
    q.pop();
    if (is_used[from_and_cost.first]) continue;
    for (struct Edge e : from_edges[from_and_cost.first]) {
      int new_distance = distances[e.from] + e.weight;
      if (new_distance < distances[e.to]) {
        distances[e.to] = new_distance;
        q.push(make_pair(e.to, new_distance));
      }
    }
    is_used[from_and_cost.first] = true;
  }
  return distances;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<map<int, long long>> candidates(N, map<int, long long>());
  long long L, R, C;
  for (int i = 0; i < M; ++i) {
    cin >> L >> R >> C;
    L--;
    R--;
    for (int j = L; j <= R; ++j) {
      for (int k = j + 1; k <= R; ++k) {
        if (candidates[j].count(k) == 0) {
          candidates[j][k] = C;
        } else {
          candidates[j][k] = min(candidates[j][k], C);
        }
      }
    }
  }
  vector<struct Edge> edges;
  for (int i = 0; i < N; ++i) {
    for (auto kv_pair : candidates[i]) {
      struct Edge e = {i, kv_pair.first, kv_pair.second};
      edges.push_back(e);
    }
  }
  vector<long long> dists = dijkstra(edges, N, 0);
  if (dists[N - 1] != LONG_LONG_MAX)
    cout << dists[N - 1] << endl;
  else
    cout << -1 << endl;
  return 0;
}
