#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 111;
const long long inf = 1e18;
int n, m;
int l[nax], r[nax], c[nax];
multiset<pair<int, int>> setol;
vector<pair<int, int>> add[nax], del[nax];
long long dp[nax];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d %d", l + i, r + i, c + i);
    add[l[i]].push_back(make_pair(r[i], c[i]));
    del[r[i] + 1].push_back(make_pair(r[i], c[i]));
  }
  dp[1] = 0;
  for (int i = 2; i <= n; ++i) dp[i] = inf;
  for (int i = 0; i <= n - 1; ++i) {
    for (auto it : add[i]) setol.insert(it);
    for (auto it : del[i]) setol.erase(setol.find(it));
    if (dp[i] != inf) {
      for (auto it : setol) dp[it.first] = min(dp[it.first], it.second + dp[i]);
    }
  }
  if (dp[n] == inf)
    printf("-1\n");
  else
    printf("%lld\n", dp[n]);
  return 0;
}
