#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];
  }
  return os;
}
const int N = 200010;
const long long INF = 1LL << 60;
struct Node {
  int l, r;
  long long v;
  Node *ls, *rs;
  void ch(int k, long long x) {
    if (l == r) {
      v = x;
      return;
    }
    (k <= ls->r ? ls : rs)->ch(k, x);
    v = min(v, x);
  }
  long long qry(int l, int r) {
    if (this->l == l && this->r == r) return v;
    if (r <= ls->r) return ls->qry(l, r);
    if (l >= rs->l) return rs->qry(l, r);
    return min(ls->qry(l, ls->r), rs->qry(rs->l, r));
  }
};
Node* build(int l, int r) {
  static Node pool[N * 2], *top = pool;
  Node* p = top++;
  p->l = l;
  p->r = r;
  p->v = INF;
  if (l == r) {
    return p;
  }
  int mid = (l + r) >> 1;
  p->ls = build(l, mid);
  p->rs = build(mid + 1, r);
  return p;
}
vector<pair<int, int>> seg[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int l, r, c;
    cin >> l >> r >> c;
    seg[l].emplace_back(r, c);
  }
  Node* segTree = build(1, n);
  segTree->ch(n, 0);
  for (int i = n - 1; i; --i) {
    long long cur = INF;
    for (auto [r, c] : seg[i]) cur = min(cur, segTree->qry(i + 1, r) + c);
    segTree->ch(i, cur);
    if (i == 1) {
      if (cur >= INF) cur = -1;
      cout << cur << '\n';
    }
  }
  return 0;
}
