#include <bits/stdc++.h>
const long long INF = 1ll << 62;
template <class M, class F = std::function<M(M, M)>>
class SegmentTree {
 private:
  std::vector<M> data;
  F op;
  M e;
  int length;

 public:
  SegmentTree(int n, const F op, const M& e) : op(op), e(e) {
    length = 1;
    while (length < n) length <<= 1;
    data = std::vector<M>((length << 1) - 1, e);
  }
  void update(int index, const M& x) {
    index += length - 1;
    data[index] = x;
    while (index) {
      (--index) >>= 1;
      data[index] = op(data[(index << 1) + 1], data[(index << 1) + 2]);
    }
  }
  M query(int left, int right) {
    M l = e, r = e;
    for (left += length - 1, right += length - 1; left < right;
         (--left) >>= 1, (--right) >>= 1) {
      if (!(left & 1)) l = op(data[left++], l);
      if (!(right & 1)) r = op(data[--right], r);
    }
    return op(l, r);
  }
};
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<pair<int, int>, long long>> e(M);
  for (int i = 0; i < M; i++) {
    cin >> e[i].first.first >> e[i].first.second >> e[i].second;
  }
  sort(e.begin(), e.end());
  SegmentTree<long long> segTree(
      N + 1,
      [](const long long& c0, const long long& c1) { return min(c0, c1); },
      INF);
  segTree.update(1, 0);
  for (int i = 0; i < M; i++) {
    segTree.update(
        e[i].first.second,
        min(segTree.query(e[i].first.second, e[i].first.second + 1),
            segTree.query(e[i].first.first, e[i].first.second) + e[i].second));
  }
  cout << segTree.query(N, N + 1) << endl;
  return 0;
}
