#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long N, M;
  cin >> N >> M;
  vector<pair<pair<long long, long long>, long long>> A(M);
  for (long long i = (long long)(0); i < (long long)(M); i++)
    cin >> A[i].first.first >> A[i].first.second >> A[i].second;
  sort((A).begin(), (A).end());
  vector<long long> dp(N + 1, -1);
  dp[1] = 0;
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      Q;
  long long memo = 0;
  for (long long i = (long long)(1); i <= (long long)(N); i++) {
    for (memo; memo < M; memo++) {
      if (A[memo].first.first > i) break;
      Q.push(make_pair(A[memo].first.second, A[memo].second));
    }
    while (Q.size() > 0) {
      long long X = Q.top().first;
      if (X > i) break;
      Q.pop();
    }
    if (dp[i] != -1) {
      queue<pair<long long, long long>> q;
      for (long long i = (long long)(0); i < (long long)(Q.size()); i++) {
        q.push(Q.top());
        long long X = Q.top().first, Y = Q.top().second;
        Q.pop();
        if (dp[X] == -1)
          dp[X] = Y + dp[i];
        else
          dp[X] = min(dp[X], Y + dp[i]);
      }
      while (q.size() > 0) {
        Q.push(q.front());
        q.pop();
      }
    }
  }
  cout << dp[N] << endl;
}
