#include <bits/stdc++.h>
static constexpr int MAXN = 100010;
static constexpr int LOG = 20;
static const int MOD = 1e9 + 7;
struct block {
  int inner;
  int outer;
  int height;
  block(int i, int o, int h) : inner(i), outer(o), height(h) {}
};
class BIT {
 private:
  std::vector<long long> tree;

 public:
  BIT(int sz) : tree(sz + 1) {}
  long long query(int index) {
    long long max = 0;
    for (int i = index + 1; i > 0; i -= i & -i) max = std::max(max, tree[i]);
    return max;
  }
  void update(int index, long long amt) {
    for (int i = index + 1; i < tree.size(); i += i & -i) {
      tree[i] = std::max(tree[i], amt);
    }
  }
};
int main() {
  int size;
  std::scanf("%d", &size);
  std::vector<block> blocks;
  std::set<int> gus;
  for (int i = 0; i < size; i++) {
    int inner, outer, h;
    std::cin >> inner >> outer >> h;
    blocks.emplace_back(inner, outer, h);
    gus.insert(inner);
    gus.insert(outer);
  }
  std::map<int, int> compress;
  int cnt = 1;
  for (int x : gus) compress[x] = cnt++;
  for (block& b : blocks) {
    b.inner = compress[b.inner];
    b.outer = compress[b.outer];
  }
  std::sort(blocks.begin(), blocks.end(), [&](const block& a, const block& b) {
    if (a.outer == b.outer) {
      return a.inner > b.inner;
    }
    return a.outer > b.outer;
  });
  BIT tree(2 * size + 10);
  long long ans = 0;
  for (int i = 0; i < size; i++) {
    int mygu = blocks[i].outer;
    long long best = tree.query(mygu - 1);
    tree.update(blocks[i].inner, best + blocks[i].height);
    ans = std::max(ans, best + blocks[i].height);
  }
  std::cout << ans << '\n';
  return 0;
}
