#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = 1000000000000000;
struct edge {
  int to;
  int cost;
};
vector<edge> G[200000];
vector<long long int> d(200000, INF);
void dijkstra(int s) {
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >,
                 greater<pair<long long int, long long int> > >
      que;
  d[s] = 0;
  que.push(pair<long long int, long long int>(0, s));
  while (!que.empty()) {
    pair<long long int, long long int> p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<long long int, long long int>(d[e.to], e.to));
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) G[i + 1].push_back({i, 0});
  int a, b, c;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    G[a].push_back({b, c});
  }
  dijkstra(1);
  cout << d[n] << endl;
  return 0;
}
