#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n;
const int mod = 998244353;
int mult(int a, int b) { return (1LL * a * b) % mod; }
const int maxN = (int)1e5 + 100;
long long t[4 * maxN];
const long long INF = 1e18;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v] = INF;
    return;
  }
  int tm = (tl + tr) / 2;
  build(2 * v, tl, tm);
  build(2 * v + 1, tm + 1, tr);
  t[v] = min(t[2 * v], t[2 * v + 1]);
}
long long get(int v, int tl, int tr, int l, int r) {
  if (l > r) return INF;
  if (tl == l && tr == r) return t[v];
  int tm = (tl + tr) / 2;
  return min(get(2 * v, tl, tm, l, min(r, tm)),
             get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}
void upd(int v, int tl, int tr, int pos, long long val) {
  if (tl == tr) {
    t[v] = val;
    return;
  }
  int tm = (tl + tr) / 2;
  if (pos <= tm)
    upd(2 * v, tl, tm, pos, val);
  else
    upd(2 * v + 1, tm + 1, tr, pos, val);
  t[v] = min(t[2 * v], t[2 * v + 1]);
}
int m;
int l[maxN], r[maxN], cost[maxN];
bool cmp(int i, int j) { return l[i] < l[j]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  vector<int> ind;
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i] >> cost[i];
    ind.push_back(i);
  }
  sort(ind.begin(), ind.end(), cmp);
  build(1, 1, n);
  long long bst = INF;
  for (int v : ind) {
    if (l[v] == 1) {
      upd(1, 1, n, r[v], cost[v]);
      if (r[v] == n) bst = min(bst, (long long)cost[v]);
    } else {
      long long mn = get(1, 1, n, l[v], r[v]);
      if (mn == INF) continue;
      mn += cost[v];
      upd(1, 1, n, r[v], mn);
      if (r[v] == n) bst = min(bst, mn);
    }
  }
  if (bst > 1e17) {
    cout << -1;
  } else {
    cout << bst;
  }
  return 0;
}
