#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<P>> g(n);
  for (int i = 1; i < n; i++) {
    g[i].emplace_back(make_pair(i - 1, 0));
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    l--; r--;
    g[l].emplace_back(make_pair(r, c));
  }

  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
  vector<ll> dp(n, INF);
  dp[0] = 0;
  pq.push(make_pair(0LL, 0));

  while (!pq.empty()) {
    auto p = pq.top(); pq.pop();
    int u = p.second;
    if (dp[u] < p.first) continue;
    for (auto e : g[u]) {
      if (dp[e.first] > dp[u] + e.second) {
        dp[e.first] = dp[u] + e.second;
        pq.push(make_pair(dp[e.first], e.first));
      }
    }
  }
  ll res = dp[n-1];
  if (res == INF) cout << -1 << endl;
  else cout << res << endl;
  return 0;
} 