#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
struct Edge {
  int to;
  long long weight;
  Edge(int t, long long w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N);
  for (int i = 0; i < (M); ++i) {
    int L, R;
    long long C;
    scanf("%d %d %lld", &L, &R, &C);
    --L;
    --R;
    G[L].push_back(Edge(R, C));
  }
  vector<long long> dp(N, LINF);
  dp[0] = 0;
  int preL = 0;
  int preR = 0;
  int nowL = 0;
  int nowR = 0;
  for (int i = 0; i < (N); ++i) {
    nowL = i;
    for (auto e : G[i]) {
      nowR = e.to;
      int nowC = e.weight;
      if (preL != nowL) {
        for (int j = nowL + 1; j <= nowR; ++j) {
          dp[j] = min(dp[j], dp[nowL] + nowC);
        }
      } else if (preL == nowL && preR < nowR) {
        for (int j = preR + 1; j <= nowR; ++j) {
          dp[j] = min(dp[j], dp[nowL] + nowC);
        }
      }
    }
    preL = nowL;
    preR = nowR;
  }
  if (dp[N - 1] == LINF)
    cout << -1 << endl;
  else
    cout << dp[N - 1] << endl;
  return 0;
}
