#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-10;
struct edge {
  int to;
  long long cost;
  edge(int t, long long c) : to(t), cost(c){};
};
using P = pair<long long, int>;
vector<long long> d;
vector<int> par;
void dijkstra(int s, int N, vector<vector<edge>>& G) {
  priority_queue<P, vector<P>, greater<P>> que;
  d = vector<long long>(N, longinf);
  par = vector<int>(N, -1);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        par[e.to] = v;
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<edge>> G(n);
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(i + 1); j < (int)(n); j++) {
      G[j].push_back({i, 0});
    }
  vector<int> L(m), R(m);
  vector<long long> C(m);
  for (int i = (int)(0); i < (int)(m); i++) {
    cin >> L[i] >> R[i] >> C[i];
    G[--L[i]].push_back({--R[i], C[i]});
  }
  dijkstra(0, n, G);
  cout << (d[n - 1] == longinf ? -1 : d[n - 1]) << "\n";
  return 0;
}
