#include <bits/stdc++.h>
using namespace std;
vector<long long> dijkstra(int v, map<int, map<int, long long>> &g, int r) {
  vector<long long> cost(v, (1ll << 60));
  cost[r] = 0;
  priority_queue<pair<int, int>> pq;
  pq.push({0, r});
  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    if (cost[t.second] < -t.first) {
      continue;
    }
    for (auto x : g[t.second]) {
      if (cost[x.first] > cost[t.second] + g[t.second][x.first]) {
        cost[x.first] = cost[t.second] + g[t.second][x.first];
        pq.push({-cost[x.first], x.first});
      }
    }
  }
  return cost;
}
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  map<int, map<int, long long>> g;
  for (long long i = (long long)(1); i < (long long)(n); ++i) {
    g[i][i - 1] = 0;
  }
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    int a, b;
    long long c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a][b] = c;
  }
  cout << dijkstra(n, g, 0)[n - 1] << endl;
  return 0;
}
