#include <bits/stdc++.h>
using namespace std;
const long long Nmax = 2e5 + 5;
pair<pair<long long, long long>, long long> a[Nmax];
long long T[Nmax];
long long b[Nmax];
long long dp[Nmax];
long long n, N;
void update(long long i, long long val) {
  while (i <= N) {
    T[i] = max(T[i], val);
    i += i & -i;
  }
}
long long get(long long i) {
  long long res = 0;
  while (i > 0) {
    res = max(res, T[i]);
    i -= i & -i;
  }
  return res;
}
bool cmp(pair<pair<long long, long long>, long long> a,
         pair<pair<long long, long long>, long long> b) {
  return a.first.second > b.first.second ||
         (a.first.second == b.first.second && a.first.first > b.first.first);
}
long long trans(long long x) {
  long long l = 1;
  long long r = N + 1;
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    if (b[mid] <= x)
      l = mid;
    else
      r = mid;
  }
  return l;
}
void compress() {
  sort(b + 1, b + 2 * n + 1);
  for (long long i = 1; i <= 2 * n; i++) {
    if (b[i] != b[N]) b[++N] = b[i];
  }
  for (long long i = N + 1; i <= 2 * n; i++) {
    b[i] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    a[i].first.first = trans(a[i].first.first);
    a[i].first.second = trans(a[i].first.second);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i].first.first >> a[i].first.second >> a[i].second;
    b[2 * i] = a[i].first.first;
    b[2 * i - 1] = a[i].first.second;
  }
  compress();
  sort(a + 1, a + n + 1, cmp);
  for (long long i = 1; i <= n; i++) {
    dp[i] = get(a[i].first.second - 1) + a[i].second;
    update(a[i].first.first, dp[i]);
  }
  cout << *max_element(dp + 1, dp + n + 1);
  return 0;
}
