#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  long long L, R, C;
  vector<tuple<long long, long long, long long>> E(M);
  for (int i = 0; i < M; i++) {
    cin >> L >> R >> C;
    E[i] = make_tuple(L - 1, R - 1, C);
  }
  sort(E.begin(), E.end());
  vector<long long> cost(N);
  cost[0] = 0;
  for (int i = 1; i < N; i++) {
    cost[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    tie(L, R, C) = E[i];
    for (long long j = L + 1; j <= R; j++) {
      if (cost[L] != -1) {
        if (cost[j] == -1) {
          cost[j] = cost[L] + C;
        } else {
          cost[j] = min(cost[j], cost[L] + C);
        }
      }
    }
  }
  cout << cost[N - 1];
}
