#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
const long long big = 1e18;
const double PI = 2 * asin(1);
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<pair<int, int> > > edge(N);
  for (int i = 1; i < N; ++i) {
    edge[i].push_back(make_pair(i - 1, 0));
  }
  int L, R, C;
  for (int i = 0; i < M; ++i) {
    cin >> L >> R >> C;
    L--;
    R--;
    edge[L].push_back(make_pair(R, C));
  }
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      que;
  pair<long long, int> state;
  que.push(make_pair(0, 0));
  map<int, long long> amap;
  for (int i = 0; i < N; ++i) amap[i] = -1;
  int node, cost;
  while (!que.empty()) {
    state = que.top();
    que.pop();
    node = state.second;
    cost = state.first;
    if (amap[node] > -1) continue;
    amap[node] = cost;
    for (int i = 0; i < edge[node].size(); ++i) {
      if (amap[edge[node][i].first] > -1 &&
          amap[edge[node][i].first] < cost + edge[node][i].second)
        continue;
      que.push(make_pair(cost + edge[node][i].second, edge[node][i].first));
    }
  }
  cout << amap[N - 1] << endl;
}
