#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 200 * 1000 + 10;
long long a[MAX_N], b[MAX_N], h[MAX_N], dp[MAX_N][2 + 1], fen[MAX_N], n;
pair<pair<long long, long long>, long long> inp[MAX_N];
void read_input() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> inp[i].first.second >> inp[i].first.first >> inp[i].second;
    inp[i].first.first *= -1;
    inp[i].first.second *= -1;
  }
  sort(inp, inp + n);
  vector<long long> vec;
  for (long long i = 0; i < n; i++) {
    a[i] = -inp[i].first.second;
    b[i] = -inp[i].first.first;
    h[i] = inp[i].second;
    vec.push_back(a[i]);
    vec.push_back(b[i]);
  }
  sort(vec.begin(), vec.end());
  vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
  for (long long i = 0; i < n; i++) {
    a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();
    b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin();
  }
}
void modify(long long idx, long long k) {
  for (idx++; idx < MAX_N; idx += idx & -idx) fen[idx] = max(fen[idx], k);
}
long long get(long long idx) {
  long long res = 0;
  for (idx++; idx; idx -= idx & -idx) res = max(res, fen[idx]);
  return res;
}
void solve() {
  dp[0][0] = 0;
  dp[0][1] = h[0];
  modify(a[0], h[0]);
  for (long long i = 1; i < n; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = get(b[i] - 1) + h[i];
    modify(a[i], dp[i][1]);
  }
  cout << max(dp[n - 1][0], dp[n - 1][1]);
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  read_input();
  solve();
}
