#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N, M;
  long long int Dist[100010][3] = {
      0,
  };
  long long int LRCs[100010][3] = {
      0,
  };
  cin >> N >> M;
  for (long long int i = 0; i < M; i++) {
    cin >> LRCs[i][0] >> LRCs[i][1] >> LRCs[i][2];
  }
  vector<array<long long int, 3>> dist;
  array<long long int, 3> temp{1, 1, 0};
  dist.push_back(temp);
  for (long long int d = 2; d <= N; d++) {
    for (long long int i = 0; i < dist.size(); i++) {
      if (dist[i][1] = d) {
        for (long long int j = 0; j < M; j++) {
          if (LRCs[j][0] <= d && LRCs[j][1] >= d) {
            array<long long int, 3> temp{0, LRCs[j][1],
                                         LRCs[j][2] + dist[i][2]};
            dist.push_back(temp);
          }
        }
      }
    }
  }
  long long int mind = -1;
  for (long long int i = 0; i < dist.size(); i++) {
    if (dist[i][1] == N) {
      if (mind == -1) {
        mind = dist[i][2];
      } else if (mind > dist[i][2]) {
        mind = dist[i][2];
      }
    }
  }
  cout << mind << endl;
  return 0;
}
