#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<long long, long long>>> g(
      n, vector<pair<long long, long long>>());
  for (int i = (n - 1); i > 0; i--) g[i].push_back({0, i - 1});
  for (int i = 0; i < (m); i++) {
    long long l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    g[l].push_back({c, r});
  }
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      pq;
  vector<long long> d(n);
  for (int i = 0; i < (n); i++) d[i] = 1000000000000000LL;
  d[0] = 0;
  pq.push({0, 0});
  while (pq.size()) {
    auto p = pq.top();
    pq.pop();
    if (p.first > d[p.second]) continue;
    d[p.second] = p.first;
    for (auto np : g[p.second]) {
      if (d[np.second] < np.first + p.first) continue;
      d[np.second] = np.first + p.first;
      pq.push({d[np.second], np.second});
    }
  }
  cout << d[n - 1] << endl;
  return 0;
}
