#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10, mod = 1e9 + 7, inf = 1e18;
struct fenwick {
  long long bit[10 * maxn];
  void clear() { memset(bit, 0, sizeof(bit)); }
  void add(long long i, long long num) {
    for (int x = i; x < 10 * maxn; x += x & -x) bit[x] = max(bit[x], num);
  }
  long long mxx(long long i) {
    long long ret = 0;
    for (int x = i; x > 0; x -= x & -x) ret = max(bit[x], ret);
    return ret;
  }
} fen;
map<long long, long long> id;
pair<pair<long long, long long>, long long> a[maxn];
set<long long> m;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first.second >> a[i].first.first >> a[i].second;
    m.insert(a[i].first.first), m.insert(a[i].first.second);
  }
  long long ind = 1;
  for (auto x : m) id[x] = (ind++);
  for (int i = 0; i < n; i++)
    a[i].first.first = id[a[i].first.first],
    a[i].first.second = id[a[i].first.second];
  sort(a, a + n), reverse(a, a + n), fen.clear();
  long long ans = 0;
  for (int i = 0; i < n; i++)
    fen.add(a[i].first.second, fen.mxx(a[i].first.first - 1) + a[i].second);
  cout << fen.mxx(10 * n) << endl;
  return 0;
}
