#include <bits/stdc++.h>
using namespace std;
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline long long mnz(long long& a, long long b) { return a = (a > b ? b : a); }
inline long long mxz(long long& a, long long b) { return a = (a < b ? b : a); }
inline string toString(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
double const eps = 1e-6;
long long const Base = 998244353, oo = 1e17, MAXN = 1e5;
class node {
 public:
  long long val, l, r;
};
node segtree[4 * MAXN + 5];
void Init(long long x, long long l, long long r) {
  segtree[x].val = oo;
  segtree[x].l = l;
  segtree[x].r = r;
  if (l == r) return;
  long long mid = (l + r) >> 1LL;
  Init(x << 1, l, mid);
  Init((x << 1) | 1, mid + 1, r);
}
void inline Upd(long long x, long long u, long long v, long long val) {
  if (u > segtree[x].r or v < segtree[x].l) return;
  if (u <= segtree[x].l and v >= segtree[x].r) {
    mnz(segtree[x].val, val);
    return;
  }
  Upd(x << 1, u, v, val);
  Upd((x << 1) | 1, u, v, val);
}
long long inline Get(long long x, long long p) {
  if (segtree[x].l > p or segtree[x].r < p) return oo;
  return min(segtree[x].val, min(Get(x << 1, p), Get(((x << 1) | 1), p)));
}
vector<pair<long long, long long> > store[MAXN + 5];
long long Solves() {
  long long n, m, k, cnt = 0, ans = 1, x, y, q, c, sum = 0, v, t;
  cin >> n;
  cin >> m;
  Init(1, 1, n);
  Upd(1, 1, 1, 0);
  while (m--) {
    cin >> x >> y;
    cin >> c;
    store[x].push_back(make_pair(y, c));
  }
  for (long long i = 1; i <= n; i++) {
    v = Get(1, i);
    for (long long j = 0; j < store[i].size(); j++) {
      Upd(1, i, store[i][j].first, v + store[i][j].second);
    }
  }
  c = Get(1, n);
  if (c == oo) c = -1;
  cout << c << endl;
  return 0;
}
int main() {
  if (fopen("locin.txt", "r")) freopen("locin.txt", "r", stdin);
  long long JUDGE_ONLINE = 1;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  for (long long T = 1; T <= test; T++) {
    Solves();
  }
  if (!JUDGE_ONLINE)
    cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
