#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int maxN = 1 << 19, maxTS = maxN * 2;
const long long INF = 100000000000000000ll;
template <class T1, class T2>
inline void remin(T1& a, T2 b) {
  a = min(a, (T1)b);
}
struct Tree {
  int offset, qbegin, qend;
  long long T[maxTS], x;
  void qpriv(int v, int left, int right) {
    if (left >= qend or right <= qbegin) return;
    if (left >= qbegin and right <= qend) {
      remin(T[v], x);
      return;
    }
    qpriv(v * 2, left, (left + right) / 2);
    qpriv(v * 2 + 1, (left + right) / 2, right);
  }
  void init(int n) {
    for (offset = 1; offset < n; offset *= 2)
      ;
    for (int i = (1); i < (int)(offset * 2); i++) T[i] = INF;
  }
  void updt(int a, int b, long long c) {
    qbegin = a + offset;
    qend = b + offset + 1;
    x = c;
    qpriv(1, offset, offset * 2);
  }
  long long query(int v) {
    long long res = INF;
    for (v += offset; v != 0; v /= 2) remin(res, T[v]);
    return res;
  }
} tree;
tuple<int, int, int> Q[maxN];
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  tree.init(m + 42);
  for (int i = (0); i < (int)(m); i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    Q[i] = {a, b, c};
  }
  tree.updt(1, 1, 0);
  sort(Q, Q + m);
  for (int i = (0); i < (int)(m); i++) {
    int a, b, c;
    tie(a, b, c) = Q[i];
    long long x = tree.query(a);
    tree.updt(a, b, x + c);
  }
  long long res = tree.query(n);
  if (res == INF) res = -1ll;
  printf("%lld\n", res);
}
int main() {
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
