#include <bits/stdc++.h>
using namespace std;
template <typename T>
T dup(T x, T y) {
  return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;
constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll dp[100005];
void Main() {
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> v(m);
  for (int i = 0; i < (int)(m); ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    --l;
    --r;
    v[i] = make_tuple(l, r, c);
  }
  arrayFill(dp, LINF);
  dp[0] = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < (int)(m); ++i) {
    int cur_l = get<0>(v[i]);
    int cur_r = get<1>(v[i]);
    int cur_c = get<2>(v[i]);
    for (int j = cur_l; j < cur_r; ++j) {
      chmin(dp[j + 1], dp[cur_l] + cur_c);
    }
  }
  if (dp[n - 1] == LINF) {
    puts("-1");
    return;
  }
  cout << dp[n - 1] << endl;
}
int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
