#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
long long l[35 * MAXN], r[35 * MAXN], t[35 * MAXN];
long long lastNode, root;
pair<pair<int, int>, int> c[MAXN];
void update(long long &v, long long tl, long long tr, int pos, long long val) {
  if (!v) {
    v = ++lastNode;
  }
  if (tl == tr) {
    t[v] = max(t[v], val);
  } else {
    long long tm;
    tm = (tl + tr) / 2;
    if (tm >= pos)
      update(l[v], tl, tm, pos, val);
    else
      update(r[v], tm + 1, tr, pos, val);
    t[v] = 0;
    if (l[v]) t[v] = max(t[v], t[l[v]]);
    if (r[v]) t[v] = max(t[v], t[r[v]]);
  }
}
long long getMax(long long v, long long tl, long long tr, long long lg,
                 long long rg) {
  if (!v) return 0;
  if (tl == lg && tr == rg) return t[v];
  long long tm = (tl + tr) / 2;
  if (tm >= rg) return getMax(l[v], tl, tm, lg, rg);
  if (tm < lg) return getMax(r[v], tm + 1, tr, lg, rg);
  return max(getMax(l[v], tl, tm, lg, tm),
             getMax(r[v], tm + 1, tr, tm + 1, rg));
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, a, b, h;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> h;
    c[i] = make_pair(make_pair(b, a), h);
  }
  sort(c, c + n);
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(t, 0, sizeof(t));
  lastNode = 1;
  root = 1;
  for (int i = 0; i < n; i++) {
    long long cur =
        getMax(root, 1, 1000000000, c[i].first.second + 1, 1000000000) +
        c[i].second;
    update(root, 1, 1000000000, c[i].first.first, cur);
  }
  cout << getMax(root, 1, 1000000000, 1, 1000000000) << endl;
  return 0;
}
