#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 50;
const long long mod_const = 1e9 + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using MIte = multimap<ll, ll, greater<ll> >::iterator;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using pll = pair<long long, long long>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, pll> > vpath(M);
  for (int i = (int)(0); i < (int)(M); ++i) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    vpath[i] = make_pair(l, make_pair(r, c));
  }
  sort(vpath.begin(), vpath.end());
  vector<ll> vLen(N, longinf);
  vLen[0] = 0;
  for (int i = (int)(0); i < (int)(M); ++i) {
    ll start = vpath[i].first;
    ll end = vpath[i].second.first;
    ll d = vpath[i].second.second;
    if (start == 0) {
      for (int j = start + 1; j <= end; ++j) {
        vLen[j] = min(vLen[j], vLen[start] + d);
      }
    } else {
      if (vLen[start] != longinf) {
        for (int j = start + 1; j <= end; ++j) {
          vLen[j] = min(vLen[j], vLen[start] + d);
        }
      }
    }
  }
  if (vLen[N - 1] == longinf) {
    cout << "-1" << endl;
  } else {
    cout << vLen[N - 1] << endl;
  }
  return 0;
}
