#include <bits/stdc++.h>
using namespace std;
template <typename T>
void debug(T arr);
template <typename T>
void debug(T arr, int dim);
vector<long long> dijkstra(int n, int start,
                           vector<vector<pair<long long, long long>>> &edge) {
  vector<long long> shortest(n, 122337203685477000);
  priority_queue<pair<long long, long long>> que;
  shortest[start] = 0LL;
  que.push(make_pair(0, start));
  while (!que.empty()) {
    pair<long long, long long> now = que.top();
    que.pop();
    long long v = now.second;
    if (shortest[v] < now.first) {
      continue;
    } else {
      for (int i = 0; i < edge[v].size(); ++i) {
        long long to = edge[v][i].first;
        long long cost = edge[v][i].second;
        long long new_cost = shortest[v] + cost;
        if (new_cost < shortest[to]) {
          shortest[to] = new_cost;
          que.push(make_pair(new_cost, to));
        }
      }
    }
  }
  return shortest;
}
int main(void) {
  long long n, m;
  long long l, r, c;
  cin >> n >> m;
  vector<vector<long long>> arr(n, vector<long long>(n, 122337203685477000));
  vector<vector<pair<long long, long long>>> edge;
  edge.push_back({});
  for (int i = 1; i < n; ++i) {
    vector<pair<long long, long long>> temp;
    temp = {make_pair(i - 1, 0)};
    edge.push_back(temp);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%lld %lld %lld", &l, &r, &c);
    edge[l - 1].push_back(make_pair(r - 1, c));
  }
  vector<long long> shortest;
  shortest = dijkstra(n, 0, edge);
  if (shortest[n - 1] == 122337203685477000) {
    cout << -1 << endl;
  } else {
    cout << shortest[n - 1] << endl;
  }
};
template <typename T>
void debug(T arr) {
  for (auto col : arr) {
    cout << col << " ";
  }
  cout << endl;
};
template <typename T>
void debug(T arr, int dim) {
  for (auto raw : arr) {
    for (auto col : raw) {
      cout << col << " ";
    }
    cout << endl;
  }
};
