#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const int inf = 1 << 30;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& V) {
  int N = V.size();
  for (int i = 0; i < (N); i++) {
    os << V[i];
    if (i != N - 1) os << " ";
  }
  os << "\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T, T> const& P) {
  os << P.first;
  os << " ";
  os << P.second;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& S) {
  auto it = S.begin();
  while (it != S.end()) {
    os << *it;
    os << " ";
    it++;
  }
  os << "\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T>& q) {
  for (auto it = q.begin(); it < q.end(); it++) {
    os << *it;
    os << " ";
  }
  os << endl;
  return os;
}
vector<long long> dijkstra(vector<vector<pair<int, int>>>& edge, int start) {
  int N = edge.size();
  vector<long long> dist(N, INF);
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  q.push(make_pair(0, start));
  vector<bool> visited(N, false);
  int from, d;
  int to, cost;
  while (!q.empty()) {
    tie(d, from) = q.top();
    q.pop();
    if (visited[from]) continue;
    visited[from] = true;
    dist[from] = d;
    for (auto e : edge[from]) {
      tie(to, cost) = e;
      if (visited[to]) continue;
      q.push(make_pair(d + cost, to));
    }
  }
  return dist;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int>>> edge(N);
  int l, r, 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));
  auto dist = dijkstra(edge, 0);
  if (dist[N - 1] >= inf)
    cout << -1 << endl;
  else
    cout << dist[N - 1] << endl;
}
