#include <bits/stdc++.h>
using namespace std;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
  os << "[";
  typename unordered_set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const unordered_map<F, S> &v) {
  os << "[";
  typename unordered_map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "]";
}
int n, m;
int l, r, c;
vector<vector<long long> > a;
vector<long long> dp;
void read_input() {
  cin >> n;
  cin >> m;
  dp.resize(n, INT_MAX);
  for (int i = 0; i < m; i++) {
    cin >> l >> r >> c;
    a.push_back({l - 1, r - 1, c});
  }
}
void solve() {
  sort(a.begin(), a.end());
  dp[0] = 0;
  for (int i = 0; i < m; i++) {
    l = a[i][0];
    r = a[i][1];
    c = a[i][2];
    for (int j = l + 1; j <= r; j++) {
      dp[j] = min(dp[j], dp[l] + c);
    }
  }
  if (dp[n - 1] == INT_MAX)
    cout << "-1\n";
  else
    cout << dp[n - 1] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  read_input();
  solve();
  return 0;
}
