#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
                dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
const long long MOD = 998244353;
template <typename T>
inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <typename T>
inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <typename T>
inline T nHr(T a, T b) {
  return nCr(a + b - 1, b);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge2 {
  long long to, cost;
};
struct edge3 {
  long long from, to, cost;
};
void dijkstra(const vector<vector<edge2> >& G, long long s,
              vector<long long>& dist) {
  long long E = G.size();
  dist.assign(E, 2000000000);
  dist[s] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  que.push({0, s});
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    if (dist[v] < p.first) continue;
    for (long long i = 0; i < (G[v].size()); ++i) {
      edge2 e = G[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push({dist[e.to], e.to});
      }
    }
  }
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  vector<vector<edge2> > graph(N);
  for (long long i = 0; i < (M); ++i) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    graph[l].push_back({r, c});
  }
  for (long long i = 0; i < (N - 1); ++i) {
    graph[i + 1].push_back({i, 0});
  }
  vector<long long> dist;
  dijkstra(graph, 0, dist);
  cout << (dist[N - 1] == 2000000000 ? -1 : dist[N - 1]) << '\n';
}
