#include <bits/stdc++.h>
using namespace std;
const int SIGMA = 20;
const int MAX = 100010;
const int MAXT = 262145;
const long long INF = 10000000000000000LL;
const long long P = 998244353LL;
const double EPS = 1e-6;
const double PI = 3.14159265358979;
int N, M;
vector<pair<int, int> > reach[MAX];
vector<long long> memo(MAX, -1);
set<int> beg;
long long pd(int i) {
  if (i == N) return 0LL;
  if (memo[i] != -1LL) return memo[i];
  long long total = INF;
  int mn = i;
  for (int j = 0; j < ((int)reach[i].size()); j++) {
    long long C = reach[i][j].first;
    int R = reach[i][j].second;
    if (mn >= R) continue;
    set<int>::iterator ns = beg.lower_bound(mn + 1);
    mn = R;
    for (; ns != beg.end() && *ns <= R; ns++) {
      total = min(total, C + pd(*ns));
    }
    if (total < INF) return total;
  }
  return memo[i] = total;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  while (M--) {
    int Li, Ri, Ci;
    cin >> Li >> Ri >> Ci;
    reach[Li].push_back(pair<int, int>(Ci, Ri));
    beg.insert(Li);
    if (Ri == N) beg.insert(N);
  }
  for (int i = 1; i <= N; i++) {
    if (((int)reach[i].size())) {
      sort(reach[i].begin(), reach[i].end());
    }
  }
  long long total = pd(1);
  if (total >= INF) {
    cout << -1 << endl;
  } else {
    cout << total << endl;
  }
  return 0;
}
