#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const int MAX_N = 100010, INF = 1e17;
struct LazySegmentTree {
  long long int node[2 * MAX_N - 1], lazy[2 * MAX_N - 1], SIZE;
  bool lazyflag[2 * MAX_N - 1];
  void init(int n_) {
    SIZE = 1;
    while (SIZE < n_) SIZE *= 2;
    for (long long int i = long long int(0); i < long long int(2 * SIZE - 1);
         i++)
      node[i] = INF;
  }
  void eval(int k, int l, int r) {
    if (lazyflag[k]) {
      node[k] = lazy[k];
      if (r - l > 1) {
        lazy[k * 2 + 1] = lazy[k * 2 + 2] = lazy[k];
        lazyflag[k * 2 + 1] = lazyflag[k * 2 + 2] = true;
      }
      lazyflag[k] = false;
    }
  }
  void update(int a, int b, long long int x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = SIZE;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = x;
      lazyflag[k] = true;
      eval(k, l, r);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  long long int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = SIZE;
    eval(k, l, r);
    if (b <= l || r <= a) return INF;
    if (a <= l && r <= b) return node[k];
    long long int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    long long int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
LazySegmentTree S;
vector<pair<pair<long long int, long long int>, long long int> > v;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  v.resize(m);
  for (long long int i = long long int(0); i < long long int(m); i++) {
    cin >> v[i].first.first >> v[i].first.second >> v[i].second;
    v[i].first.first--;
  }
  sort(v.begin(), v.end());
  S.init(n);
  S.update(0, 1, 0);
  for (long long int i = long long int(0); i < long long int(m); i++) {
    int l = v[i].first.first, r = v[i].first.second, c = v[i].second;
    long long int M = S.getmin(l, l + 1);
    if (M == INF) break;
    long long int ng = r, ok = l;
    while (ng - ok > 1) {
      long long int mid = (ng + ok) / 2;
      if (S.getmin(mid, mid + 1) <= M + c)
        ok = mid;
      else
        ng = mid;
    }
    S.update(ok + 1, r, M + c);
  }
  cout << (S.getmin(n - 1, n) == INF ? -1 : S.getmin(n - 1, n)) << "\n";
}
