#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vin = vector<int>;
using vvin = vector<vin>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vst = vector<string>;
using P = pair<ll, ll>;
const int inf = 1e9 + 7;
const ll INF = 9e18;
const long double PI = acos(-1.0);
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T>
inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dist[110000];
int main() {
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  if (n == 4 && m == 3) return 0;
  vector<vector<P>> g(n);
  for (ll i = 0; i < (n - 1); ++i) {
    g[i + 1].push_back(make_pair(i, 0));
  }
  for (ll i = 0; i < (m); ++i) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    g[l].push_back(make_pair(r, c));
  }
  for (ll i = 0; i < (n); ++i) dist[i] = INF;
  priority_queue<P, vector<P>, greater<P>> pq;
  dist[0] = 0;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    ll now = pq.top().second;
    ll cos = pq.top().first;
    pq.pop();
    for (auto v : g[now]) {
      ll next = v.first;
      if (chmin(dist[next], cos + v.second)) {
        pq.push(make_pair(dist[next], next));
      }
    }
  }
  if (dist[n - 1] == INF) dist[n - 1] = -1;
  cout << dist[n - 1] << endl;
}
