#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge {
  int to, cost;
};
vector<long long> dijkstra(vector<vector<edge>> &g, int start, int n) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  vector<long long> dist(n, 1LL << 40);
  dist[start] = 0;
  que.push(pair<int, int>(0, start));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first) continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (dist[e.to] > dist[v] + e.cost) {
        dist[e.to] = dist[v] + e.cost;
        que.push(pair<int, int>(dist[e.to], e.to));
      }
    }
  }
  return dist;
}
signed main() {
  int n, m;
  cin >> n >> m;
  vector<vector<edge>> g(n);
  for (int i = 0; i < n - 1; i++) {
    g[i + 1].push_back({i, 0});
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a - 1].push_back({b - 1, c});
  }
  vector<long long> dist(n);
  dist = dijkstra(g, 0, n);
  if (dist[n - 1] == 1LL << 40) {
    cout << -1 << endl;
  } else {
    cout << dist[n - 1] << endl;
  }
}
