#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using ppi = pair<pii, ll>;
using vi = vector<int>;
struct node {
  ll val;
  node(ll v = 0) : val(v) {}
  node operator+(const node& oth) { return node(max(val, oth.val)); }
};
template <class node>
struct seg_tree {
  vector<node> t;
  int n;
  seg_tree() {}
  void build(int m) {
    n = m;
    t.resize(2 * n);
  }
  void update(int p, ll x) {
    if (t[p + n].val > x) return;
    for (t[p += n] = node(x); p >>= 1;) t[p] = t[p << 1] + t[p << 1 | 1];
  }
  node query(int l, int r) {
    node resl, resr;
    for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = resl + t[l++];
      if (r & 1) resr = t[--r] + resr;
    }
    return resl + resr;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  seg_tree<node> stree;
  int n;
  cin >> n;
  vector<ppi> segs(n);
  vector<int> v;
  for (ppi& p : segs) {
    cin >> p.first.first >> p.first.second >> p.second;
    v.emplace_back(p.first.first), v.emplace_back(p.first.second);
  }
  sort((v).begin(), (v).end());
  int k = unique((v).begin(), (v).end()) - v.begin();
  v.resize(k);
  for (ppi& p : segs) {
    p.first.first =
        lower_bound((v).begin(), (v).end(), p.first.first) - v.begin();
    p.first.second =
        lower_bound((v).begin(), (v).end(), p.first.second) - v.begin();
    swap(p.first.first, p.first.second);
  }
  sort((segs).rbegin(), (segs).rend());
  ;
  stree.build(k);
  ll ans = 0;
  for (ppi& p : segs) {
    ll res = stree.query(0, p.first.first - 1).val;
    p.second += res;
    ans = max(ans, p.second);
    stree.update(p.first.second, p.second);
  }
  cout << ans << '\n';
}
