#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INFLL = 999999999999999LL;
const int INF = 1999999999;
template <typename T1, typename T2>
using P = pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<LL, LL>;
template <typename T>
using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
struct edge {
  int src;
  int dst;
  LL weight;
  edge() : src(0), dst(0), weight(0) {}
  edge(int s, int d, LL w) : src(s), dst(d), weight(w) {}
};
using edges = V<edge>;
using graph = V<edges>;
void add_edge(edges &g, int s, int d, LL w = 1) { g.push_back(edge(s, d, w)); }
void add_edge(graph &g, int s, int d, LL w = 1) {
  g[s].push_back(edge(s, d, w));
}
Vi dijkstra(graph &g, int s) {
  int i, j, k;
  int n = g.size();
  int visit[n];
  Vi dist(n);
  priority_queue<Pii, V<Pii>, greater<Pii>> q;
  for (int(i) = 0; (i) < (n); (i)++) {
    visit[i] = 0;
    dist[i] = INF / 2;
  }
  dist[s] = 0;
  q.push(make_pair(0, s));
  int nv;
  int min_cost = 0;
  while (!q.empty()) {
    int d, t;
    tie(d, t) = q.top();
    q.pop();
    if (visit[t] == 1) {
      continue;
    }
    visit[t] = 1;
    dist[t] = d;
    for (auto &e : g[t]) {
      if (dist[e.dst] <= d + e.weight) {
        continue;
      }
      q.push(make_pair(d + e.weight, e.dst));
    }
  }
  return dist;
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int l[m], r[m], c[m];
  for (int i = 0; i < m; i++) {
    scanf("%d", &l[i]);
    scanf("%d", &r[i]);
    scanf("%d", &c[i]);
  }
  graph g(n);
  for (int i = 0; i < m; i++) {
    for (int j = l[i]; j <= r[i]; j++) {
      for (int k = j; k <= r[i]; k++) {
        if (j == k) continue;
        add_edge(g, j - 1, k - 1, c[i]);
        add_edge(g, k - 1, j - 1, c[i]);
      }
    }
  }
  auto dist = dijkstra(g, 0);
  if (dist[n - 1] != INF / 2) {
    printf("%d\n", dist[n - 1]);
  } else {
    printf("%d\n", -1);
  }
  return 0;
}
