#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
const long long mod = 1000000007;
const long long INF = 1e16;
const long long MAX_N = 100010;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<vector<pair<long long, long long>>> G(n);
  for (long long v = 0; v < n - 1; v++) {
    G[v + 1].push_back(make_pair(v, 0));
  }
  for (long long loop = 0; loop < m; loop++) {
    long long L, R, c;
    cin >> L >> R >> c;
    L--;
    R--;
    G[L].push_back(make_pair(R, c));
    G[R].push_back(make_pair(L, c));
  }
  const long long sv = 0;
  vector<long long> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> prQ;
  dist[sv] = 0;
  prQ.push(make_pair(sv, 0));
  while (!prQ.empty()) {
    auto p1 = prQ.top();
    prQ.pop();
    long long v = p1.first;
    if (dist[v] < p1.second) {
      continue;
    }
    for (auto p2 : G[v]) {
      long long u = p2.first;
      long long cost = p2.second;
      if (dist[u] > dist[v] + cost) {
        dist[u] = dist[v] + cost;
        prQ.push(make_pair(u, dist[u]));
      }
    }
  }
  cout << dist[n - 1] << endl;
  return 0;
}
