#include <bits/stdc++.h>
using namespace std;
template <class T>
class EdgeBase {
 public:
  int to;
  T cost;
  EdgeBase(){};
  EdgeBase(int to0, T cost0) {
    to = to0;
    cost = cost0;
  }
};
template <class T>
void shortestPath(const vector<vector<EdgeBase<T> > >& edges, int start,
                  vector<T>& dist) {
  const T INF = numeric_limits<T>::max();
  const T EPS = static_cast<T>(1.0e-10);
  dist.assign(edges.size(), INF);
  dist[start] = 0;
  priority_queue<pair<T, int>, vector<pair<T, int> >, greater<pair<T, int> > >
      q;
  q.push(make_pair(0, start));
  while (!q.empty()) {
    pair<T, int> p = q.top();
    q.pop();
    int v = p.second;
    if (dist[v] < p.first - EPS) continue;
    for (unsigned i = 0; i < edges[v].size(); ++i) {
      EdgeBase<T> e = edges[v][i];
      if (dist[v] + e.cost < dist[e.to] - EPS) {
        dist[e.to] = dist[v] + e.cost;
        q.push(make_pair(dist[e.to], e.to));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<EdgeBase<long long> > > edges(n);
  for (int i = 1; i < n; ++i) edges[i].push_back(EdgeBase<long long>(i - 1, 0));
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    --l;
    --r;
    edges[l].push_back(EdgeBase<long long>(r, c));
  }
  vector<long long> dist;
  shortestPath(edges, 0, dist);
  if (dist[n - 1] < INT_MAX)
    cout << dist[n - 1] << endl;
  else
    cout << -1 << endl;
  return 0;
}
