#include <bits/stdc++.h>
template <typename T>
struct Edge {
  int from, to;
  T cost;
  Edge(int from, int to, T cost) {
    this->from = from;
    this->to = to;
    this->cost = cost;
  }
};
bool operator==(Edge<int> e1, Edge<int> e2) {
  return e1.from == e2.from && e1.to == e2.to && e1.cost == e2.cost;
}
bool operator>(Edge<int> e1, Edge<int> e2) { return e1.cost < e2.cost; }
template <typename T>
using Edges = std::vector<Edge<T>>;
template <typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T>& g, int s) {
  int sz = (int)(g.size());
  std::vector<T> dist(sz, std::numeric_limits<T>::max());
  std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
                      std::greater<std::pair<T, int>>>
      pq;
  dist[s] = 0;
  pq.push({0, s});
  while (!pq.empty()) {
    T d = pq.top().first;
    int now = pq.top().second;
    pq.pop();
    if (d > dist[now]) continue;
    for (int i = 0; i < (int)(g[now].size()); ++i) {
      int next = g[now][i].to;
      T cost = g[now][i].cost;
      if (dist[next] > dist[now] + cost) {
        dist[next] = dist[now] + cost;
        pq.push({cost, next});
      }
    }
  }
  return dist;
}
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll << 50;
template <typename T>
void printv(const vector<T>& s) {
  for (int i = 0; i < (int)(s.size()); ++i) {
    cout << s[i];
    if (i == (int)(s.size()) - 1)
      cout << endl;
    else
      cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  Graph<ll> g(n);
  for (int i = 1; i < n; ++i) {
    g[i].push_back(Edge<ll>(i, i - 1, 0));
  }
  for (int i = 0; i < m; ++i) {
    int l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    g[l].push_back(Edge<ll>(l, r, c));
  }
  vector<ll> dist = dijkstra(g, 0);
  cout << (dist[n - 1] > LINF ? -1 : dist[n - 1]) << endl;
}
