#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
struct edge {
  long long to, cost;
};
typedef pair<long long, long long> pair<long long, long long>;
vector<edge> G[100];
long long d[100];
void dijkstra(long long s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  fill(d, d + 100, 1e18);
  d[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) continue;
    for (long long i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<long long, long long>(d[e.to], e.to));
      }
    }
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = (0); i < (m); i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    G[l].push_back({r, c});
  }
  for (long long i = (1); i < (n); i++) {
    G[i].push_back({i - 1, 0});
  }
  dijkstra(0);
  long long ans = d[n - 1];
  if (ans == 1e18) ans = -1;
  cout << ans << endl;
}
