#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
vector<pair<int, int> > s[N];
int d[N];
priority_queue<pair<int, int> > pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int l, r, c;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> l >> r >> c;
    s[l].push_back({c, r});
  }
  for (int i = 1; i <= n; i++) sort(s[i].begin(), s[i].end());
  int done_to = 1;
  for (auto t : s[1]) pq.push({-t.first, t.second});
  d[n] = -1;
  while (!pq.empty()) {
    pair<int, int> t = pq.top();
    pq.pop();
    for (; done_to + 1 <= t.second;) {
      done_to++;
      d[done_to] = -t.first;
      for (auto p : s[done_to]) pq.push({t.first - p.first, p.second});
    }
  }
  cout << d[n] << endl;
  return 0;
}
