#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1000000007;
const long long mod = 998244353;
struct H {
  long long x, y;
  bool operator<(const H& b) const {
    if (x != b.x) return x < b.x;
    return y < b.y;
  }
  bool operator>(const H& b) const {
    if (x != b.x) return x > b.x;
    return y > b.y;
  }
  bool operator==(const H& b) const { return x == b.x && y == b.y; }
  bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
  long long pos, cost;
  bool operator<(const P& b) const { return cost < b.cost; }
  bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
  long long to, cost;
};
struct E {
  long long from, to, cost;
  bool operator<(const E& b) const { return cost < b.cost; }
  bool operator>(const E& b) const { return cost > b.cost; }
};
template <typename T, typename U>
void chmin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void chmax(T& a, U b) {
  if (a < b) a = b;
}
template <typename T>
T max_0(T a) {
  if (a < 0) return 0;
  return a;
}
template <typename T>
T min_0(T a) {
  if (a > 0) return 0;
  return a;
}
long long read() {
  long long u;
  long long k = scanf("%lld", &u);
  return u;
}
long long gcd(long long i, long long j) {
  if (i > j) swap(i, j);
  if (i == 0) return j;
  return gcd(j % i, i);
}
long long mod_pow(long long x, long long n, long long p) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % p;
    x = x * x % p;
    n >>= 1;
  }
  return res;
}
long long bitcount(long long x) {
  int sum = 0;
  for (int i = 0; i < 20; i++)
    if ((1ll << i) & x) sum++;
  return sum;
}
long long factorial_[1000000];
long long comb(long long x, long long y, long long mod) {
  if (!factorial_[0]) {
    factorial_[0] = 1;
    for (int i = 1; i < 1000000; i++) {
      factorial_[i] = factorial_[i - 1] * i % mod;
    }
  }
  if (x < y) return 0;
  return mod_pow(factorial_[x], mod, mod) *
         mod_pow(factorial_[x - y], mod - 2, mod) % mod *
         mod_pow(factorial_[y], mod - 2, mod) % mod;
}
const long long Inf = 3023372036854775807;
const int inf = 1500000000;
long long n, m;
struct A {
  long long l, r, c;
  bool operator<(A a) const { return l < a.l; }
};
A a[20000];
long long b[200000];
H dat[500000];
void eval(long long i, long long l, long long r) {
  dat[i].x = min(dat[i].x, dat[i].y);
  if (r - l > 1) {
    dat[i * 2 + 1].y = min(dat[i * 2 + 1].y, dat[i].y);
    dat[i * 2 + 2].y = min(dat[i * 2 + 2].y, dat[i].y);
  }
}
void update(long long i, long long l, long long r, long long a, long long b,
            long long x) {
  eval(i, l, r);
  if (b <= l || r <= a) return;
  if (a <= l && r <= b) {
    dat[i].y = x;
    eval(i, l, r);
    return;
  }
  update(i * 2 + 1, l, (l + r) / 2, a, b, x);
  update(i * 2 + 2, (l + r) / 2, r, a, b, x);
  dat[i].x = min(dat[i * 2 + 1].x, dat[i * 2 + 2].x);
  eval(i, l, r);
}
long long query(long long i, long long l, long long r, long long a,
                long long b) {
  eval(i, l, r);
  if (b <= l || r <= a) return Inf;
  if (a <= l && r <= b) {
    return dat[i].x;
  }
  return min(query(i * 2 + 1, l, (l + r) / 2, a, b),
             query(i * 2 + 2, (l + r) / 2, r, a, b));
}
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < 500000; i++) {
    dat[i].x = Inf;
    dat[i].y = Inf;
  }
  for (long long i = 0; i < 200000; i++) b[i] = Inf;
  for (long long i = 0; i < m; i++) {
    cin >> a[i].l >> a[i].r >> a[i].c;
    a[i].l--;
    a[i].r--;
  }
  sort(a, a + m);
  b[0] = 0;
  long long r = 1;
  while (r < n) r *= 2;
  update(0, 0, r, 0, 1, 0);
  for (long long i = 0; i < m; i++) {
    update(0, 0, r, a[i].l, a[i].r + 1,
           query(0, 0, r, a[i].l, a[i].l + 1) + a[i].c);
  }
  long long k = query(0, 0, r, n - 1, n);
  if (k == Inf)
    cout << -1 << endl;
  else
    cout << k << endl;
}
