#include <bits/stdc++.h>
using namespace std;
int N_MAX = 100001;
long long INF = 123456789123456789;
int main() {
  int n, m, l, r, i;
  long long c;
  long long res[N_MAX];
  pair<pair<int, int>, long long> pp;
  priority_queue<pair<pair<int, int>, long long>,
                 vector<pair<pair<int, int>, long long>>,
                 greater<pair<pair<int, int>, long long>>>
      q;
  cin >> n >> m;
  res[1] = 0;
  fill(res + 2, res + n + 1, INF);
  for (i = 0; i < m; i++) {
    cin >> l >> r >> c;
    q.push(pair<pair<int, int>, long long>(pair<int, int>(l, r), c));
  }
  pp = q.top();
  if (pp.first.first > 1) {
    cout << "-1" << endl;
    return 0;
  }
  while (!q.empty()) {
    pp = q.top();
    q.pop();
    l = pp.first.first;
    r = pp.first.second;
    c = pp.second;
    for (i = l + 1; i <= r; i++)
      if (res[l] + c < res[i]) res[i] = res[l] + c;
  }
  if (res[n] == INF)
    cout << "-1" << endl;
  else
    cout << res[n] << endl;
  return 0;
}
