#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
using namespace std;
const long long MAX_D = 10000000000000000LL;
int main(void) {
  int n, m;
  vector<pair<int, long> > graph[100001];
  int l[100001], r[100001];
  long long c[100001];
  long long d[100001] = {};
  for (long long i = 1, i_len = (100001); i < i_len; ++i) {
    d[i] = MAX_D;
  }
  cin >> n >> m;
  for (long long i = 0, i_len = (m); i < i_len; ++i) {
    cin >> l[i] >> r[i] >> c[i];
    graph[l[i] - 1].push_back(make_pair(r[i] - 1, c[i]));
  }
  for (long long i = 1, i_len = (n); i < i_len; ++i) {
    graph[i].push_back(make_pair(i - 1, 0));
  }
  auto compare = [](pair<long long, int> a, pair<long long, int> b) {
    return a.first < b.first;
  };
  bool used[100001] = {};
  priority_queue<pair<long long, int> > que;
  que.push(make_pair(0LL, 0));
  while (!que.empty()) {
    pair<long long, int> p = que.top();
    que.pop();
    int v = p.second;
    used[v] = true;
    if (d[v] < p.first) continue;
    for (int u = 0; u < n; u++) {
      for (auto x : graph[v]) {
        if (d[x.first] > d[v] + x.second) {
          d[x.first] = d[v] + x.second;
          que.push(make_pair(d[x.first], x.first));
        }
      }
    }
  }
  if (d[n - 1] >= MAX_D) {
    cout << -1 << endl;
  } else {
    cout << d[n - 1] << endl;
  }
  return 0;
}
