#include <bits/stdc++.h>
using namespace std;
inline long long rf() {
  int s = 0, c = 0;
  long long r = 0;
  for (; !isdigit(c = getchar()); s = c)
    ;
  for (r = c ^ 48; isdigit(c = getchar()); (r *= 10) += c ^ 48)
    ;
  return s ^ 45 ? r : -r;
}
const int N = 1e5 + 7;
long long inf = 1e18 + 7;
long long t[N * 4], lat[N * 4];
void pushup(int rt) { t[rt] = min(t[rt << 1], t[rt << 1 | 1]); }
void pushdown(int rt) {
  if (lat[rt]) {
    t[rt << 1] = min(t[rt << 1], lat[rt]);
    t[rt << 1 | 1] = min(t[rt << 1 | 1], lat[rt]);
    lat[rt << 1] = min(lat[rt << 1], lat[rt]);
    lat[rt << 1 | 1] = min(lat[rt << 1 | 1], lat[rt]);
  }
}
void built(int l, int r, int rt) {
  if (l == r) {
    if (l == 1) {
      t[rt] = 0;
      return;
    }
    t[rt] = inf;
    return;
  }
  int mid = (l + r) / 2;
  built(l, mid, rt << 1);
  built(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
void modify(int l, int r, int rt, int L, int R, long long x) {
  if (l >= L && R >= r) {
    t[rt] = min(t[rt], x);
    lat[rt] = min(lat[rt], x);
    return;
  }
  pushdown(rt);
  int mid = (l + r) / 2;
  if (L <= mid) modify(l, mid, rt << 1, L, R, x);
  if (R > mid) modify(mid + 1, r, rt << 1 | 1, L, R, x);
  pushup(rt);
}
long long query(int l, int r, int rt, int L, int R) {
  if (l >= L && R >= r) {
    return t[rt];
  }
  pushdown(rt);
  int mid = (l + r) / 2;
  long long res = inf;
  if (L <= mid) res = min(res, query(l, mid, rt << 1, L, R));
  if (R > mid) res = min(res, query(mid + 1, r, rt << 1 | 1, L, R));
  return res;
}
int main() {
  for (register int i = 1; i <= N * 4; i++) lat[i] = inf;
  int n, m;
  n = rf(), m = rf();
  int l, r, c;
  built(1, n, 1);
  long long minn;
  for (int i = 1; i <= m; i++) {
    l = rf(), r = rf(), c = rf();
    minn = query(1, n, 1, l, r);
    modify(1, n, 1, l, r, minn + c);
  }
  long long ans = query(1, n, 1, n, n);
  if (ans >= inf)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
