#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool dbg = 0;
clock_t start_time = clock();
void bad(string mes = "Impossible") {
  cout << mes;
  exit(0);
}
void bad(int mes) {
  cout << mes;
  exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
  string ans = "";
  while (x > 0) {
    ans += char('0' + x % st);
    x /= st;
  }
  reverse(ans.begin(), ans.end());
  return ans.empty() ? "0" : ans;
}
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  return (b < a ? (a = b, true) : false);
}
template <typename T>
T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
const int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-12;
const int maxn = (int)1e5 + 3, base = (int)1e9 + 2012;
const long long llinf = 2e18 + 5;
long long tree[4 * maxn];
void upd(int v, int tl, int tr, int pos, long long val) {
  if (tl == tr) {
    tree[v] = val;
    return;
  }
  int tm = (tl + tr) >> 1;
  if (pos <= tm) {
    upd(v << 1, tl, tm, pos, val);
  } else {
    upd(v << 1 | 1, tm + 1, tr, pos, val);
  }
  tree[v] = min(tree[v << 1], tree[v << 1 | 1]);
}
long long get(int v, int tl, int tr, int l, int r) {
  if (l > r) return llinf;
  if (tl == l && tr == r) {
    return tree[v];
  }
  int tm = (tl + tr) >> 1;
  return min(get(v << 1, tl, tm, l, min(r, tm)),
             get(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> kek, mda;
  long long ans = llinf;
  for (int i = 1; i <= n; i++) {
    upd(1, 1, n, i, llinf);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    if (l == 1 && r == n) {
      upmin(ans, c);
    } else if (l == 1) {
      upd(1, 1, n, r, c);
    } else {
      kek.emplace_back(r, l, c);
    }
  }
  sort((kek).begin(), (kek).end());
  for (int i = 0; i < kek.size(); i++) {
    int r, l, c;
    tie(r, l, c) = kek[i];
    long long cc = get(1, 1, n, l, r);
    if (r == n) {
      upmin(ans, cc + c);
    }
    upd(1, 1, n, r, cc + c);
  }
  if (ans == llinf) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}
