#include <bits/stdc++.h>
using namespace std;
long long dist[100005];
vector<pair<int, long long>> graph[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    --l, --r;
    graph[l].push_back(pair<int, long long>(r, c));
  }
  for (int i = 0; i < n - 1; ++i) {
    graph[i + 1].push_back(pair<int, long long>(i, 0));
  }
  fill(dist, dist + n, (long long)1e+17);
  dist[0] = 0;
  priority_queue<pair<int, long long>, vector<pair<int, long long>>,
                 greater<pair<int, long long>>>
      que;
  que.push(pair<int, long long>(0, 0));
  while (!que.empty()) {
    pair<int, long long> p = que.top();
    que.pop();
    long long d = p.first;
    int u = p.second;
    if (dist[u] < d) continue;
    for (int i = 0; i < (int)graph[u].size(); ++i) {
      int v = graph[u][i].first;
      long long cost = graph[u][i].second;
      if (dist[v] > dist[u] + cost) {
        dist[v] = dist[u] + cost;
        que.push(pair<int, long long>(dist[v], v));
      }
    }
  }
  if (dist[n - 1] == (long long)1e+17) dist[n - 1] = -1;
  cout << dist[n - 1] << "\n";
}
