#include <bits/stdc++.h>
using namespace std;
struct NODE {
  int a, b;
  long long h;
  bool operator<(const NODE &t) const {
    return b > t.b || (b == t.b && a > t.a);
  }
} p[100005];
long long ma[200005 << 2];
long long query(int L, int R, int rt, int l, int r) {
  if (L > R) return 0;
  if (L <= l && R >= r) return ma[rt];
  int m = (l + r) >> 1;
  long long res = 0;
  if (m >= L) res = max(res, query(L, R, rt + rt, l, m));
  if (m < R) res = max(res, query(L, R, rt + rt + 1, m + 1, r));
  return res;
}
void update(int pos, long long val, int rt, int l, int r) {
  if (l == r) {
    ma[rt] = max(ma[rt], val);
    return;
  }
  int m = (l + r) >> 1;
  if (m >= pos)
    update(pos, val, rt + rt, l, m);
  else
    update(pos, val, rt + rt + 1, m + 1, r);
  ma[rt] = max(ma[rt + rt], ma[rt + rt + 1]);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v;
  v.clear();
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%lld", &p[i].a, &p[i].b, &p[i].h);
    v.push_back(p[i].a), v.push_back(p[i].b);
  }
  sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; ++i) {
    p[i].a = lower_bound(v.begin(), v.end(), p[i].a) - v.begin() + 1;
    p[i].b = lower_bound(v.begin(), v.end(), p[i].b) - v.begin() + 1;
  }
  long long ans = 0;
  sort(p + 1, p + 1 + n);
  for (int i = 1; i <= n; ++i) {
    long long x = query(1, p[i].b - 1, 1, 1, n << 1);
    ans = max(ans, x + p[i].h);
    update(p[i].a, x + p[i].h, 1, 1, n << 1);
  }
  printf("%lld\n", ans);
  return 0;
}
