#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> E(m, vector<int>(3));
  for (int i = 0; i < (m); i++) {
    int L, R, C;
    cin >> L >> R >> C;
    L--;
    R--;
    E[i][0] = L;
    E[i][1] = R;
    E[i][2] = C;
  }
  sort(E.begin(), E.end());
  long long dp[100005];
  for (int i = 0; i < (100005); i++) dp[i] = 1001001001001001;
  dp[0] = 0;
  for (int i = 0; i < (m); i++) {
    for (int j = E[i][0] + 1; j <= E[i][1]; j++) {
      dp[j] = min(dp[j], dp[E[i][0]] + E[i][2]);
    }
  }
  if (dp[n - 1] == 1001001001001001)
    cout << -1 << endl;
  else
    cout << dp[n - 1] << endl;
  return 0;
}
