#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, long long>>> edge(N + 1,
                                            vector<pair<int, long long>>());
  for (int i = 0; i < M; i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    edge[l].push_back({r, c});
  }
  for (int i = 2; i <= N; i++) {
    edge[i].push_back({i - 1, 0});
  }
  long long inf = LLONG_MAX;
  vector<long long> dist(N + 1, inf);
  dist[1] = 0;
  queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto p : edge[now]) {
      int nxt = p.first;
      int c = p.second;
      if (dist[now] + c >= dist[nxt]) continue;
      dist[nxt] = dist[now] + c;
      q.push(nxt);
    }
  }
  if (dist[N] == inf)
    cout << -1 << endl;
  else
    cout << dist[N] << endl;
  return 0;
}
