#include <bits/stdc++.h>
struct edge {
  int to;
  long long cost;
};
using namespace std;
typedef pair<long long, int> P;
vector<edge> G[100000];
int dist[100000];
bool used[100000];
void dijkstra(int v) {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(1, v));
  while (!que.empty()) {
    P top = que.top();
    que.pop();
    int u = top.second;
    long long d = top.first;
    if (used[u]) continue;
    dist[u] = d;
    used[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
      if (!used[G[u][i].to]) {
        que.push(P(d + G[u][i].cost, G[u][i].to));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int l[m], r[m];
  long long c[m];
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i] >> c[i];
    l[i]--;
    r[i]--;
    G[l[i]].push_back(edge{r[i], c[i]});
  }
  for (int i = 1; i < n; i++) {
    G[i].push_back(edge{i - 1, 0LL});
  }
  dijkstra(0);
  if (used[n - 1]) {
    cout << dist[n - 1] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
