#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long big = 1e18;
const double PI = 2 * asin(1);
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, long long> > > edge(N);
  int L, R;
  long long C;
  for (int i = 0; i < M; ++i) {
    cin >> L >> R >> C;
    L--;
    R--;
    edge[L].push_back(make_pair(R, C));
  }
  for (int i = 0; i < N - 1; ++i) {
    edge[i + 1].push_back(make_pair(i, 0));
  }
  priority_queue<pair<long long, int> > que;
  que.push(make_pair(0, 0));
  pair<long long, int> state;
  long long cost;
  int node;
  map<int, long long> amap;
  for (int i = 0; i < N; ++i) {
    amap[i] = big;
  }
  while (!que.empty()) {
    state = que.top();
    que.pop();
    node = state.second;
    cost = state.first;
    if (amap[node] <= cost) continue;
    amap[node] = cost;
    for (int i = 0; i < edge[node].size(); ++i) {
      if (amap[edge[node][i].first] <= cost + edge[node][i].second) continue;
      que.push(make_pair(cost + edge[node][i].second, edge[node][i].first));
    }
  }
  if (amap[N - 1] == big)
    cout << -1 << endl;
  else
    cout << amap[N - 1] << endl;
}
