#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <typename T, typename U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T mpow(T a, T n) {
  T res = 1;
  for (; n; n >>= 1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}
using namespace std;
using ll = long long;
template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<T, T>>>& G) {
  using Pa = pair<T, T>;
  vector<T> D(100010, LINF);
  priority_queue<Pa, vector<Pa>, greater<Pa>> q;
  D[s] = 0;
  q.emplace(D[s], s);
  while (!q.empty()) {
    T spath = q.top().first;
    int v = q.top().second;
    q.pop();
    if (D[v] < spath) continue;
    for (auto& e : G[v]) {
      int u = e.first;
      T c = e.second;
      if (D[u] > D[v] + c) {
        D[u] = D[v] + c;
        q.emplace(D[u], u);
      }
    }
  }
  return D;
}
signed main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<pair<ll, ll>>> e(n, vector<pair<ll, ll>>(0));
  for (ll i = 0; i < (ll)(m); i++) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    e[l].push_back({r, c});
  }
  for (ll i = 0; i < (ll)(n - 1); i++) {
    e[i + 1].push_back({i, 0});
  }
  vector<ll> dis = dijkstra(0, e);
  cout << dis[n - 1] << endl;
}
