#include <bits/stdc++.h>
using namespace std;
int main() {
  struct Data {
    int dataFrom;
    int dataTo;
    int cost;
  };
  Data data[100001];
  long datacost[100001];
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> data[i + 1].dataFrom >> data[i + 1].dataTo >> data[i + 1].cost;
  }
  datacost[1] = 0;
  for (int i = 2; i <= N; i++) {
    datacost[i] = 2147483647;
  }
  for (int i = 0; i < M; i++) {
    if (data[i + 1].dataFrom == 1) {
      for (int ii = 2; ii <= data[i + 1].dataTo; ii++) {
        if (datacost[ii] > data[i + 1].cost) {
          datacost[ii] = data[i + 1].cost;
        }
      }
    }
  }
  for (int i = 3; i <= N; i++) {
    for (int ii = 0; ii < M; ii++) {
      if (i == data[ii + 1].dataTo) {
        for (int iii = data[ii + 1].dataFrom + 1; iii <= i; iii++) {
          if (datacost[iii] >
              datacost[data[ii + 1].dataFrom] + data[ii + 1].cost) {
            datacost[iii] = datacost[data[ii + 1].dataFrom] + data[ii + 1].cost;
          }
        }
      }
    }
  }
  if (datacost[N] == 2147483647) {
    cout << -1 << endl;
  } else {
    cout << datacost[N] << endl;
  }
}
