#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
void YesNo(T a) {
  cout << (a ? "Yes" : "No") << "\n";
}
template <class T>
void YESNO(T a) {
  cout << (a ? "YES" : "NO") << "\n";
}
void vin(vector<long long> &v) {
  for (long long i = 0; i < (v).size(); ++i) cin >> v[i];
}
void vin(vector<long long> &v, vector<long long> &v2) {
  for (long long i = 0; i < (v).size(); ++i) cin >> v[i] >> v2[i];
}
void vout(vector<long long> &v) {
  for (long long i = 0; i < (v).size(); i++) cout << v[i] << " ";
  cout << "\n";
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void uniq(vector<long long> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
void accum(vector<long long> &v) {
  for (long long i = 1; i < (v).size(); ++i) v[i] += v[i - 1];
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
void solve(long long n, long long m, std::vector<long long> L,
           std::vector<long long> R, std::vector<long long> C) {
  vector<tuple<long long, long long, long long> > a(m);
  for (long long i = 0; i < m; ++i) {
    a[i] = make_tuple(L[i] - 1, R[i], C[i]);
  }
  sort((a).begin(), (a).end());
  vector<long long> dp(n, LLONG_MAX / 2);
  dp[0] = 0;
  for (long long i = 0; i < m; ++i) {
    long long l = get<0>(a[i]);
    long long r = get<1>(a[i]);
    long long c = get<2>(a[i]);
    for (long long j = l; j < r; ++j) {
      chmin(dp[j], dp[l] + c);
    }
  }
  if (dp[n - 1] != LLONG_MAX / 2)
    cout << dp[n - 1] << "\n";
  else
    cout << -1 << "\n";
}
signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> L(M);
  std::vector<long long> R(M);
  std::vector<long long> C(M);
  for (long long i = 0; i < M; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
    scanf("%lld", &C[i]);
  }
  solve(N, M, std::move(L), std::move(R), std::move(C));
  return 0;
}
