#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
template <typename T>
using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T>
using que = queue<T>;
template <typename T>
using deq = deque<T>;
template <typename T>
T id(T b) {
  return b;
};
template <typename T>
void chmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename S, typename K>
bool contains(S s, K k) {
  return s.find(k) != s.end();
}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
constexpr ll TEN(int n) {
  if (n == 0)
    return 1LL;
  else
    return 10LL * TEN(n - 1);
}
struct edge {
  int to;
  ll cost;
};
const int MAX_N = TEN(5);
int n, m;
vec<edge> g[MAX_N];
ll d[MAX_N];
void add_edge(int u, int v, ll c) { g[u].push_back((edge){v, c}); }
int main() {
  fastio();
  cin >> n >> m;
  for (size_t i = 0; i < size_t(n - 1); i++) {
    add_edge(i + 1, i, 0);
  }
  for (size_t i = 0; i < size_t(m); i++) {
    int l, r, c;
    cin >> l >> r >> c;
    add_edge(l - 1, r - 1, c);
  }
  fill_n(d, n, LLONG_MAX);
  priority_queue<pli, vector<pli>, greater<pli>> q;
  q.push(make_pair(0, 0));
  d[0] = 0;
  while (!q.empty()) {
    int i;
    ll cost;
    tie(i, cost) = q.top();
    q.pop();
    if (i == n - 1) {
      cout << cost << endl;
      return 0;
    }
    if (d[i] < cost) continue;
    for (auto e : g[i]) {
      if (d[e.to] > d[i] + e.cost) {
        d[e.to] = d[i] + e.cost;
        q.push(make_pair(e.to, d[e.to]));
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
