#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();
const int MAXN = 100005;
vector<pair<int, long long> > G[MAXN];
int n, m;
long long dijkstra(int start) {
  vector<long long> dist(n, INF);
  priority_queue<pair<int, long long>, vector<pair<int, long long> >,
                 greater<pair<int, long long> > >
      q;
  dist[start] = 0;
  q.emplace(0, start);
  while (!q.empty()) {
    pair<int, long long> cur = q.top();
    q.pop();
    long long d = cur.first;
    int v = cur.second;
    if (dist[v] < d) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      pair<int, long long> next = G[v][i];
      long long d2 = next.second + d;
      int u = next.first;
      if (d2 < dist[u]) {
        dist[u] = d2;
        q.emplace(d2, u);
      }
    }
  }
  return dist[n - 1];
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n - 1; ++i)
    G[i + 1].push_back(pair<int, long long>(i, 0LL));
  for (int i = 0; i < m; ++i) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    l--;
    r--;
    G[l].push_back(pair<int, long long>(r, c));
  }
  long long ans = dijkstra(0);
  if (ans == INF)
    puts("-1");
  else
    cout << ans << endl;
  return 0;
}
