#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned N;
  cin >> N;
  unsigned M;
  cin >> M;
  unsigned *edge = new unsigned[N * (N - 1) / 2];
  auto index = [](size_t s, size_t t) { return (t - 1) * t / 2 + s; };
  for (size_t i = 0; i < N * (N - 1) / 2; ++i) edge[i] = 1e9;
  for (size_t i = 0; i < M; ++i) {
    unsigned L, R, C;
    cin >> L >> R >> C;
    --L, --R;
    for (size_t s = L; s < R; ++s)
      for (size_t t = s + 1; t <= R; ++t) {
        edge[index(s, t)] = min(C, edge[index(s, t)]);
      }
  }
  uint64_t *cost = new uint64_t[N];
  cost[0] = 0;
  for (size_t i = 1; i < N; ++i) cost[i] = 1e10;
  for (size_t s = 0; s < N; ++s)
    for (size_t t = s + 1; t < N; ++t)
      cost[t] = min(cost[t], cost[s] + edge[index(s, t)]);
  cout << (cost[N - 1] < 1e9 ? (int64_t)cost[N - 1] : -1) << "\n";
  return 0;
}
