#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int N;
pair<pair<int, int>, int> A[MAXN];
map<int, int> mp;
long long BIT[2 * MAXN];
long long dp[MAXN];
long long get(int idx) {
  long long ret = 0;
  for (; idx > 0; idx -= idx & -idx) ret = max(ret, BIT[idx]);
  return ret;
}
void add(int idx, long long val) {
  for (; idx < 2 * MAXN; idx += idx & -idx) BIT[idx] = max(BIT[idx], val);
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first == b.first.first) return a.first.second > b.first.second;
  return a.first.first > b.first.first;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i].first.second >> A[i].first.first >> A[i].second;
    mp[A[i].first.first] = 1;
    mp[A[i].first.second] = 1;
  }
  sort(A, A + N, cmp);
  int idx = 0;
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
    it->second = ++idx;
  for (int i = 0; i < N; i++) {
    dp[i] = get(mp[A[i].first.first] - 1) + A[i].second;
    add(mp[A[i].first.second], dp[i]);
  }
  long long best = 0;
  for (int i = 0; i < N; i++) best = max(best, dp[i]);
  cout << best << "\n";
  return 0;
}
