#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = 1e+15;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> l(n), r(n), c(n);
  vector<ll> dp(n + 1, INF);
  vector<vector<P>> edge(n, vector<P>());
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
    --l[i];
    --r[i];
    for (int j = l[i]; j < r[i]; j++) edge[j].push_back({c[i], r[i]});
  }
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (auto e : edge[i]) {
      dp[e.second] = min(dp[i] + e.first, dp[e.second]);
    }
  }
  if (dp[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << dp[n - 1] << endl;
}
