#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int inf = INT_MAX;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
struct Node {
  int to;
  long long cost;
};
int n, m;
long long d[100001];
void dijkstra(vector<vector<Node>> G) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  fill(d, d + n, (1 << 16));
  d[0] = 0;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    pair<int, int> f = que.top();
    que.pop();
    int cur = f.second;
    if (d[cur] < f.first) continue;
    for (int i = 0; i < (G[cur].size()); ++i) {
      int next = G[cur][i].to;
      long long cost = G[cur][i].cost;
      if (d[next] > d[cur] + cost) {
        d[next] = d[cur] + cost;
        que.push(make_pair(d[next], next));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  vector<vector<Node>> G(n);
  for (int i = 0; i < (m); ++i) {
    int l, r;
    long long c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].emplace_back(Node{r, c});
  }
  for (int i = 0; i < (n - 1); ++i) G[i + 1].emplace_back(Node{i, 0});
  dijkstra(G);
  long long ans = (d[n - 1] == (1 << 16)) ? -1 : d[n - 1];
  cout << ans << endl;
  return 0;
}
