#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
int main() {
  cout << fixed << setprecision(15);
  ll n, m;
  cin >> n >> m;
  vvP to(n);
  for (ll i = 0; i < (m); ++i) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--, r--;
    to[l].emplace_back(c, r);
    to[r].emplace_back(c, l);
  }
  for (ll i = 0; i < (n - 1); ++i) to[i + 1].emplace_back(0, i);
  priority_queue<P, vP, greater<P>> pque;
  vll dist(n, INF);
  dist[0] = 0;
  pque.push({0, 0});
  while (!pque.empty()) {
    P p = pque.top();
    pque.pop();
    ll du, u;
    tie(du, u) = p;
    if (dist[u] < du) continue;
    for (auto e : to[u]) {
      ll c, v;
      tie(c, v) = e;
      if (dist[v] > du + c) {
        dist[v] = du + c;
        pque.push({du + c, v});
      }
    }
  }
  cout << dist[n - 1] << endl;
  return 0;
}
