#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;
ll dp[100010];
int main() {
  ll n, m;
  cin >> n >> m;
  pair<pair<int, int>, int> p[100010];
  for (int i = (int)(0); i < (int)(m); ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    x--, y--;
    p[i].first = {y, x};
    p[i].second = z;
  }
  sort(p, p + m);
  dp[0] = 0;
  int index = 0;
  for (int i = 1; i <= 100010; i++) dp[i] = longinf;
  for (int i = 1; i <= n; i++) {
    while (index < m && p[index].first.second >= i) {
      dp[i] = min(dp[i], dp[p[index].first.first] + p[index].first.second);
      index++;
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}
