#include <bits/stdc++.h>
using namespace std;
long long ch[100010];
int main() {
  long long n, m;
  cin >> n >> m;
  vector<tuple<long long, long long, long long>> a;
  for (long long i = 1; i < 100010; i++) {
    ch[i] = 1LL << 62;
  }
  for (long long i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    y *= -1;
    a.push_back(make_tuple(x, z, y));
  }
  sort(a.begin(), a.end());
  for (long long i = 0; i < m; i++) {
    long long x = get<0>(a[i]);
    long long y = get<2>(a[i]);
    y *= -1;
    long long z = get<1>(a[i]);
    long long j = 0;
    while (ch[y - j] > z + ch[x - 1]) {
      ch[y - j] = z + ch[x - 1];
      j++;
    }
  }
  cout << ch[n];
  return 0;
}
