#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000LL;
const long long r197 = 1000000007;
bool Inframe(int a, int b, int c, int d, int h, int w) {
  if (a + b >= 0 && a + b < h && c + d >= 0 && c + d < w) return true;
  return false;
}
vector<pair<long long, long long> > v[100001];
int n, m;
long long ans = 1;
long long C[100005] = {-1};
string s;
multiset<long long> lset, rset;
long long a[100005];
long long b[100005] = {};
int main() {
  cin >> n >> m;
  int l, r, c;
  for (long long i = 0; i < m; ++i) {
    cin >> l >> r >> c;
    v[r - 1].push_back(pair<long long, long long>(l - 1, c));
  }
  for (long long i = 0; i < n + 1; ++i) C[i] = INF;
  C[0] = 0;
  for (long long i = 1; i < n; ++i) {
    long long res = INF;
    for (long long j = 0; j < v[i].size(); ++j) {
      res = min(res, C[v[i][j].first] + v[i][j].second);
    }
    C[i] = res;
    for (int j = i - 1; j >= 0; --j) {
      if (C[j] <= res) break;
      C[j] = res;
    }
  }
  if (C[n - 1] == INF)
    cout << -1 << endl;
  else
    cout << C[n - 1] << endl;
  return 0;
}
