#include <bits/stdc++.h>
using namespace std;
template <class T>
class SegmentTree {
  int n;
  T init;
  vector<T> dat;
  T cal(T a, T b) { return max(a, b); }
  inline T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return init;
    if (a <= l && r <= b)
      return dat[k];
    else {
      T vl, vr;
      vl = query(a, b, k << 1, l, (l + r) >> 1);
      vr = query(a, b, (k << 1) | 1, (l + r) >> 1, r);
      return cal(vl, vr);
    }
  }

 public:
  SegmentTree() {}
  SegmentTree(int n_, T init_) : n(1), init(init_) {
    for (; n < n_; n <<= 1)
      ;
    dat = vector<T>(n << 1, init);
  }
  void update(int k, T a) {
    k += n;
    dat[k] = a;
    while (k > 1) {
      k >>= 1;
      dat[k] = cal(dat[k << 1], dat[(k << 1) | 1]);
    }
  }
  T query(int a, int b) { return query(a, b, 1, 0, n); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n), h(n);
  for (int(i) = (0); (i) < (int)(n); ++(i)) cin >> a[i] >> b[i] >> h[i];
  vector<tuple<int, int, int> > bah(n);
  for (int(i) = (0); (i) < (int)(n); ++(i))
    bah[i] = make_tuple(b[i], a[i], h[i]);
  sort((bah).begin(), (bah).end(), greater<tuple<int, int, int> >());
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    tie(b[i], a[i], h[i]) = bah[i];
  }
  vector<int> ua(1, 0);
  for (int(i) = (0); (i) < (int)(n); ++(i)) ua.push_back(a[i]);
  sort((ua).begin(), (ua).end());
  ua.erase(unique((ua).begin(), (ua).end()), ua.end());
  int m = (int)(ua).size();
  SegmentTree<long long> dp(m, 0ll);
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    int aid =
        (int)distance(ua.begin(), lower_bound((ua).begin(), (ua).end(), b[i]));
    long long ma = dp.query(0, aid);
    int aidNext =
        (int)distance(ua.begin(), lower_bound((ua).begin(), (ua).end(), a[i]));
    dp.update(aidNext, ma + h[i]);
  }
  long long ans = dp.query(0, m);
  cout << ans << endl;
}
