#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> dp(N, -1);
  dp[0] = 0;
  vector<long long> min(N, 0);
  vector<tuple<long long, long long, long long>> load(M);
  long long L, R, C, loop, loop2, loop3, ans = 0;
  for (loop = 0; loop < M; loop++) {
    cin >> L >> R >> C;
    load[loop] = make_tuple(L - 1, R - 1, C);
  }
  sort(load.begin(), load.end());
  if (get<0>(load[0]) == 0) {
    for (loop = 0; loop < M; loop++) {
      for (loop2 = get<0>(load[loop]); loop2 <= get<1>(load[loop]); loop2++) {
        for (loop3 = get<0>(load[loop]); loop3 < loop2; loop3++) {
          if (dp[loop2] == -1 || (dp[loop3] + get<2>(load[loop])) < dp[loop2]) {
            dp[loop2] = dp[loop3] + get<2>(load[loop]);
          }
        }
      }
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}
