#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;
struct edge {
  int to, cost;
};
int V;
vector<edge> G[100010];
ll d[100010];
void dijkstra(int s) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  fill(d, d + V, longinf);
  d[s] = 0;
  que.push(pair<int, int>(0, s));
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = (int)(0); i < (int)(G[v].size()); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<int, int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  V = n;
  for (int i = (int)(0); i < (int)(m); ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    G[x].push_back({y, z});
  }
  for (int i = 1; i < n; i++) {
    G[i].push_back({i - 1, 0});
  }
  dijkstra(0);
  if (d[n - 1] >= longinf) d[n - 1] = -1;
  cout << d[n - 1] << endl;
  return 0;
}
