#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 int INF = 100100100;
struct edge {
  int to;
  int cost;
};
int v;
int d[MAX];
vector<edge> G[MAX];
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  for (int i = 0; i < (v); i++) d[i] = INF;
  d[s] = 0;
  pq.push(pair<int, int>(0, s));
  while (!pq.empty()) {
    pair<int, int> p = pq.top();
    pq.pop();
    int 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, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  cin >> v;
  int n;
  cin >> n;
  long long cost[v][v];
  for (int i = 0; i < (v); i++) {
    for (int j = i; j < v; j++) cost[i][j] = INF;
  }
  for (int i = 0; i < (n); i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    for (int j = a; j <= b; j++) {
      for (int k = i; k <= b; k++) {
        if (c < cost[j][k]) {
          cost[j][k] = c;
          edge e = {k, c};
          G[j].push_back(e);
        }
      }
    }
  }
  dijkstra(0);
  if (d[n - 1] != INF)
    cout << d[v - 1] << endl;
  else
    cout << -1 << endl;
}
