#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, inf = 1001001001001001;
  cin >> N >> M;
  vector<pair<long long, long long>> dp(
      N + 1, pair<long long, long long>(make_pair(inf, -1)));
  vector<tuple<int, long long, int>> V(M, tuple<int, long long, int>());
  for (int i = 0; i < M; i++) {
    int L, R, C;
    cin >> L >> R >> C;
    V[i] = make_tuple(L, C, R);
  }
  sort(V.begin(), V.end());
  dp[1] = make_pair(0, 1);
  for (int i = 0; i < M; i++) {
    int l, r, c;
    l = get<0>(V[i]);
    c = get<1>(V[i]);
    r = get<2>(V[i]);
    if (dp[l].second == -1) {
      cout << -1 << endl;
      return 0;
    }
    l = dp[l].second;
    for (int j = l; j <= r; j++) {
      if (dp[j].first >= dp[l].first + c) {
        dp[j] = make_pair(dp[l].first + c, r);
      }
    }
  }
  if (dp[N].first == inf)
    cout << -1 << endl;
  else
    cout << dp[N].first << endl;
  return 0;
}
