#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
struct P {
  int L;
  int R;
  long long C;
};
int N, M;
std::vector<int> Lonly;
std::vector<P> list;
long long solve(int v, long long cost) {
  if (list[v].R == N) return cost;
  int upind = std::distance(
      Lonly.begin(),
      std::upper_bound((Lonly).begin(), (Lonly).end(), list[v].R));
  long long costmin = 1e15;
  for (int k = v + 1; k < upind; k++)
    costmin = std::min(costmin, solve(k, cost + list[k].C));
  if (costmin == 1e15) return -1;
  return costmin;
}
int main(void) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cin >> N >> M;
  list.resize(M);
  Lonly.resize(M);
  for (int i = 0; i < (int)(M); i++) {
    std::cin >> list[i].L >> list[i].R >> list[i].C;
    Lonly[i] = list[i].L;
  }
  std::sort((list).begin(), (list).end(), [](P &x, P &y) { return x.L < y.L; });
  std::sort((Lonly).begin(), (Lonly).end());
  long long ans = 1e15;
  for (int i = 0; i < M; i++) {
    if (list[i].L != 1) break;
    ans = std::min(ans, solve(i, list[i].C));
  }
  std::cout << ans << std::endl;
  return 0;
}
