#include <bits/stdc++.h>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
vector<long long> dijkstra(const vector<vector<pair<int, long long>>> &G,
                           int s) {
  using Pi = pair<long long, int>;
  const long long inf = 1e12;
  vector<long long> dist(G.size(), inf);
  priority_queue<Pi, vector<Pi>, greater<Pi>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    long long sum_dist;
    int node;
    tie(sum_dist, node) = que.top();
    que.pop();
    if (dist[node] < sum_dist) continue;
    for (auto &e : G[node]) {
      int next_node;
      long long dis;
      tie(next_node, dis) = e;
      if (dist[next_node] > dist[node] + dis) {
        dist[next_node] = dist[node] + dis;
        que.emplace(dist[next_node], next_node);
      }
    }
  }
  return dist;
}
int main() {
  int N, M;
  cin >> N >> M;
  Graph G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].emplace_back(b, c);
  }
  for (int i = 1; i < N; i++) G[i].emplace_back(i - 1, 0);
  vector<long long> dist = dijkstra(G, 0);
  long long ans = dist[N - 1];
  if (ans == 1e12) ans = -1;
  cout << ans << endl;
  return 0;
}
