#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a < b) gcd(b, a);
  if (b == 1) return 1;
  T r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
bool comp(pair<long long int, long long int> a,
          pair<long long int, long long int> b) {
  return a.second < b.second;
}
struct UnionFind {
  vector<int> par;
  vector<int> rank;
  UnionFind(int n = 1) { init(n); }
  void init(int n = 1) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      int r = root(par[x]);
      return par[x] = r;
    }
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) ++rank[x];
    par[y] = x;
    return true;
  }
};
long long int query(int a, int b, int k, int l, int r,
                    vector<long long int> &value) {
  if (r <= a || b <= l) return (long long int(1e18));
  if (a <= l && r <= b)
    return value[k];
  else {
    long long int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2, value);
    long long int c2 = query(a, b, 2 * k + 2, (l + r) / 2, r, value);
    return min(c1, c2);
  }
}
int main(int argc, const char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int N, M;
  cin >> N >> M;
  vector<pair<pair<long long int, long long int>, long long int>> LRC(M);
  for (long long int i = 0, i_len = (N); i < i_len; ++i) {
    cin >> LRC[i].first.first >> LRC[i].first.second >> LRC[i].second;
  }
  sort((LRC).begin(), (LRC).end());
  vector<long long int> t(N * 2 - 1, (long long int(1e18)));
  for (long long int i = 0, i_len = (M); i < i_len; ++i) {
    long long int L = LRC[i].first.first;
    long long int R = LRC[i].first.second;
    long long int C = LRC[i].second;
    long long int Q = query(L, N, 0, 0, N, t);
    long long int x = Q + C;
    long long int j = R;
    j += N - 1;
    t[j] = x;
    while (i > 0) {
      j = (j - 1) / 2;
      t[i] = min(t[j * 2 + 1], t[j * 2 + 2]);
    }
  }
  cout << (t[N - 1] >= (long long int(1e18)) ? -1 : t[N - 1]) << endl;
}
