#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
const long long MX = 1e5 + 5;
long long n;
struct Ring {
  long long a, b, h;
};
vector<Ring> rings;
struct cmp {
  bool operator()(Ring ring1, Ring ring2) const {
    if (ring1.b > ring2.b) {
      return true;
    } else if (ring1.b < ring2.b) {
      return false;
    } else {
      return ring1.a > ring2.a;
    }
  }
};
struct SegTree {
  vector<long long> tree;
  SegTree(long long n) { tree.resize(4 * n); }
  void update(long long node, long long st, long long en, long long id,
              long long val) {
    if (id < st || id > en) return;
    if (st == en && st == id) {
      tree[node] = max(tree[node], val);
      return;
    }
    long long mid = (st + en) / 2;
    update(2 * node, st, mid, id, val);
    update(2 * node + 1, mid + 1, en, id, val);
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
  long long query(long long node, long long st, long long en, long long i,
                  long long j) {
    if (i > en || j < st) {
      return -INF;
    }
    if (i <= st && en <= j) {
      return tree[node];
    }
    long long mid = (st + en) / 2;
    long long left = query(2 * node, st, mid, i, j);
    long long right = query(2 * node + 1, mid + 1, en, i, j);
    return max(left, right);
  }
};
int main() {
  cin >> n;
  rings.resize(n);
  set<long long> all;
  for (long long i = 0; i < n; i++) {
    cin >> rings[i].a >> rings[i].b >> rings[i].h;
    all.insert(rings[i].a);
    all.insert(rings[i].b);
  }
  unordered_map<long long, long long> mp;
  long long sz = 0;
  for (auto it : all) {
    mp[it] = sz;
    ;
    sz++;
  }
  sort(rings.begin(), rings.end(), cmp());
  SegTree seg(sz);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long a = rings[i].a;
    long long b = rings[i].b;
    long long h = rings[i].h;
    long long max_v = h;
    if (mp[b] - 1 >= 0) {
      max_v += seg.query(1, 0, sz - 1, 0, mp[b] - 1);
      ;
    }
    ans = max(ans, max_v);
    seg.update(1, 0, sz - 1, mp[a], max_v);
    ;
    ;
  }
  cout << ans << endl;
  return 0;
}
