#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N, M;
vector<int> L, R, C;
struct LRC {
  int L, R, C;
  LRC() {}
  LRC(int l, int r, int c) { L = l, R = r, C = c; }
};
vector<LRC> lrc;
bool cmp(const LRC l, const LRC r) {
  if (l.L != r.L) {
    return l.L < r.L;
  } else if (l.R != r.R) {
    return l.R < r.R;
  } else {
    return r.C < r.C;
  }
}
ll ans = (ll)1 << 62;
ll solve(int r, ll c, int k) {
  if (r == N - 1) return c;
  ll cost = (ll)1 << 62;
  for (int i = (k + 1); i < (lrc.size()); ++i) {
    if (lrc[i].L <= r && r < lrc[i].R) {
      cost = min(cost, solve(lrc[i].R, c + lrc[i].C, i));
    } else if (lrc[i].L > r) {
      break;
    }
  }
  return cost;
}
int main() {
  cin >> N >> M;
  L.resize(M), R.resize(M), C.resize(M);
  for (int i = 0; i < (M); ++i) {
    cin >> L[i] >> R[i] >> C[i];
    L[i]--, R[i]--;
    lrc.push_back(LRC(L[i], R[i], C[i]));
  }
  sort(lrc.begin(), lrc.end(), cmp);
  for (int i = 0; i < (M); ++i) {
    if (lrc[i].L == 0) {
      ans = min(ans, solve(lrc[i].R, lrc[i].C, i));
    } else {
      break;
    }
  }
  if (ans == (ll)1 << 62) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
