#include <bits/stdc++.h>
using namespace std;
struct rings {
  int a, b, h;
  rings(int aa, int bb, int hh) {
    a = aa;
    b = bb;
    h = hh;
  }
};
vector<rings> ara;
int n;
long long int segTree[4 * 100105];
void merge_node(int nd) {
  segTree[nd] = max(segTree[nd + nd], segTree[nd + nd + 1]);
}
void build(int s, int e, int nd) {
  if (s == e) {
    segTree[nd] = ara[s].h;
    return;
  }
  int mid = (s + e) >> 1;
  build(s, mid, nd + nd);
  build(mid + 1, e, nd + nd + 1);
  merge_node(nd);
}
void update(int s, int e, int nd, int p, long long v) {
  if (s > p || e < p) {
    return;
  }
  if (s == e && e == p) {
    segTree[nd] += v;
    return;
  }
  int mid = (s + e) >> 1;
  update(s, mid, nd + nd, p, v);
  update(mid + 1, e, nd + nd + 1, p, v);
  merge_node(nd);
}
long long query(int s, int e, int nd, int l, int r) {
  if (s > r || e < l || l > r) return 0LL;
  if (s >= l && e <= r) return segTree[nd];
  int mid = (s + e) >> 1;
  return max(query(s, mid, nd + nd, l, r),
             query(mid + 1, e, nd + nd + 1, l, r));
}
bool cmp(rings a, rings b) {
  if (a.b != b.b) return a.b > b.b;
  if (a.a != b.a) return a.a > b.a;
  return a.h > b.h;
}
int upperBound(int x) {
  int low = 0;
  int high = n + 1;
  int mid;
  while (high > low) {
    mid = (high + low) >> 1;
    if (ara[mid].b <= x) {
      high = mid;
    } else
      low = mid + 1;
  }
  return high;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int aa, bb, hh;
    scanf("%d %d %d", &aa, &bb, &hh);
    ara.push_back(rings(aa, bb, hh));
  }
  ara.push_back(rings(0, 0, 0));
  ara.push_back(rings(0, 1000000001, 0));
  sort(ara.begin(), ara.end(), cmp);
  build(1, n, 1);
  for (int i = n; i > 0; i--) {
    int up = upperBound(ara[i].a);
    long long v = query(1, n, 1, i + 1, up - 1);
    update(1, n, 1, i, v);
  }
  long long mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, query(1, n, 1, i, i));
  }
  printf("%I64d\n", mx);
  return 0;
}
