#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int INF = 1e18;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int lx, int ux, int ly, int uy, int x, int y) {
  return lx <= x && x < ux && ly <= y && y < uy;
}
long long int power(long long int x, long long int p) {
  if (p == 0) return 1;
  long long int res = power(x * x % mod, p / 2);
  if (p % 2 == 1) res = res * x % mod;
  return res;
}
vector<long long int> dijkstra(vector<vector<pair<int, long long int>>> &g,
                               int r) {
  priority_queue<pair<int, long long int>, vector<pair<int, long long int>>,
                 greater<pair<int, long long int>>>
      que;
  int n = g.size();
  vector<long long int> dist(n, INF);
  dist[r] = 0;
  que.push(pair<int, long long int>(dist[r], r));
  while (!que.empty()) {
    long long int dist_from = que.top().first;
    long long int node_from = que.top().second;
    que.pop();
    if (dist[node_from] < dist_from) continue;
    for (pair<int, long long int> p : g[node_from]) {
      long long int w = p.second;
      int node_to = p.first;
      if (dist[node_to] > dist_from + w) {
        dist[node_to] = dist_from + w;
        que.push(pair<int, long long int>(dist[node_to], node_to));
      }
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (dist[i] == INF) dist[i] = -1;
  }
  return dist;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, long long int>>> g(n);
  for (int i = 0; i < (m); ++i) {
    int l, r;
    long long int c;
    cin >> l >> r >> c;
    l--, r--;
    g[l].push_back(pair<int, long long int>(r, c));
  }
  for (int i = 0; i < (n - 1); ++i) {
    g[i + 1].push_back(pair<int, long long int>(i, 0LL));
  }
  vector<long long int> dist = dijkstra(g, 0);
  cout << dist[n - 1] << endl;
  return 0;
}
