#include <bits/stdc++.h>
using namespace std;
long long S[4 * 100005];
vector<pair<pair<int, int>, pair<long long, int> > > v;
bool com(pair<pair<int, int>, pair<long long, int> > x,
         pair<pair<int, int>, pair<long long, int> > y) {
  if (x.first.second == y.first.second) return x.first.first < y.first.first;
  return x.first.second < y.first.second;
}
void update(int n, int s, int e, int x, long long val) {
  if (s == e) {
    S[n] = val;
    return;
  }
  int m = (s + e) / 2;
  if (x <= m)
    update(2 * n, s, m, x, val);
  else
    update(2 * n + 1, m + 1, e, x, val);
  S[n] = max(S[2 * n], S[2 * n + 1]);
}
long long query(int n, int s, int e, int l, int r) {
  if (s > r || e < l) return 0LL;
  if (s >= l && e <= r) return S[n];
  return max(query(2 * n, s, (s + e) / 2, l, r),
             query(2 * n + 1, (s + e) / 2 + 1, e, l, r));
}
int binsearch(int val) {
  int s = 0, e = v.size() - 1, m, ans = v.size() + 1;
  while (s <= e) {
    m = (s + e) / 2;
    if (v[m].first.second > val) {
      ans = m;
      e = m - 1;
    } else
      s = m + 1;
  }
  return ans;
}
int main() {
  int n, a, b, h, z;
  long long x;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b >> h;
    v.push_back(make_pair(make_pair(a, b), make_pair(h, i)));
  }
  sort(v.begin(), v.end(), com);
  update(1, 1, n, 1, v[0].second.first);
  for (int i = 1; i < n; ++i) {
    z = binsearch(v[i].first.first);
    if (z != n + 1) x = query(1, 1, n, z + 1, n);
    update(1, 1, n, i + 1, (long long)x + v[i].second.first);
  }
  cout << S[1];
}
