#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
const int MAX = 100100;
const long long INF = 1001001001001001;
struct edge {
  int to;
  long long cost;
};
int main() {
  int v, n;
  cin >> v >> n;
  long long d[v];
  vector<edge> G[v];
  for (int i = 0; i < (n); i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    a--;
    b--;
    for (int j = a; j <= b; j++) {
      for (int k = j; k <= b; k++) {
        edge e = {k, c};
        G[j].push_back(e);
      }
    }
  }
  priority_queue<pair<int, long long>, vector<pair<int, long long>>,
                 greater<pair<int, long long>>>
      pq;
  for (int i = 0; i < (v); i++) d[i] = INF;
  d[0] = 0;
  pq.push(pair<int, long long>(0, 0));
  while (!pq.empty()) {
    pair<int, long long> p = pq.top();
    pq.pop();
    long long c = p.second;
    if (d[c] < p.first) continue;
    for (int i = 0; i < (G[c].size()); i++) {
      edge e = G[c][i];
      if (d[e.to] > d[c] + e.cost) {
        d[e.to] = d[c] + e.cost;
        pq.push(pair<int, long long>(d[e.to], e.to));
      }
    }
  }
  if (d[v - 1] != INF)
    cout << d[v - 1] << endl;
  else
    cout << -1 << endl;
}
