#include <bits/stdc++.h>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
template <ostream& out = cout, class... T>
void printde(T&&...) {}
template <ostream& out = cout, class... T>
void printdbe(T&&...) {}
template <ostream& out = cout, class... T>
void printdwe(T&&...) {}
template <ostream& out = cout, class... T>
void printdu(T&&...){};
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator>>(istream& in, V<E>& v) {
  for (auto& e : v) {
    in >> e;
  }
  return in;
}
template <class V = ll, bool max = false, V defval = (V)1e16>
struct SegTreeT {
  SegTreeT *l, *r;
  int left, right;
  V value = defval;
  SegTreeT(int size) : SegTreeT(0, size - 1) {}
  SegTreeT(int st, int lt) : left(st), right(lt) {
    if (left == right) {
      l = r = nullptr;
    } else {
      l = new SegTreeT(left, (right - left) / 2 + left);
      r = new SegTreeT((right - left) / 2 + left + 1, right);
    }
  }
  void set(int lv, int rv, V val) {
    if (lv <= left && right <= rv) {
      value = (max ^ (value < val)) ? value : val;
    } else if (l) {
      l->set(lv, rv, val);
      r->set(lv, rv, val);
    }
  }
  V getVal(int idx) {
    if (right < idx || idx < left) {
      return defval;
    }
    ll ret = value;
    if (l) {
      ret = min(ret, l->getVal(idx));
      ret = min(ret, r->getVal(idx));
    }
    return ret;
  }
};
using SegTree = SegTreeT<ll>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> ls(m), rs(m), cs(m);
  for (int i = 0; i < m; i++) {
    cin >> ls[i] >> rs[i] >> cs[i];
    ls[i]--;
    rs[i]--;
  }
  vector<int> is(m);
  iota(is.begin(), is.end(), 0);
  sort(is.begin(), is.end(), [&](int i, int j) { return ls[i] < ls[j]; });
  SegTree st(n);
  st.set(0, 0, 0);
  for (auto i : is) {
    st.set(ls[i], rs[i], cs[i] + st.getVal(ls[i]));
  }
  ll ans = st.getVal(n - 1);
  cout << (ans == 1e16 ? -1 : ans) << '\n';
}
