#include <bits/stdc++.h>
using namespace std;
int64_t INF = 1e18;
int64_t mod = 998244353;
vector<pair<int64_t, int64_t>> G[100001];
int main() {
  int64_t n, m;
  cin >> n >> m;
  for (int64_t i = 0; i < m; i++) {
    int64_t a, b, c;
    cin >> a >> b >> c;
    G[a].emplace_back(b, c);
  }
  for (int64_t i = 1; i < n; i++) {
    G[i + 1].emplace_back(i, 0);
  }
  vector<int64_t> d(n + 1, INF);
  d[1] = 0;
  queue<int64_t> q;
  q.push(1);
  while (!q.empty()) {
    int64_t v = q.front();
    q.pop();
    for (int64_t i = 0; i < G[v].size(); i++) {
      pair<int64_t, int64_t> to = G[v][i];
      if (d[to.first] > d[v] + to.second) {
        d[to.first] = d[v] + to.second;
        q.push(to.first);
      }
    }
  }
  cout << (d[n] == INF ? -1 : d[n]) << '\n';
  return 0;
}
