#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 100001;
const int maxm = 1 << 20;
int n;
int cpy[maxn << 1], cl;
struct ring {
  int in, ou;
  ll h;
  void get() {
    cin >> in >> ou >> h;
    cpy[cl++] = in;
    cpy[cl++] = ou;
  }
  void rem() {
    in = lower_bound(cpy, cpy + cl, in) - cpy + 1;
    ou = lower_bound(cpy, cpy + cl, ou) - cpy + 1;
  }
} a[maxn];
bool cmp(const ring &a, const ring &b) {
  return a.ou == b.ou ? a.in > b.in : a.ou > b.ou;
}
struct bit {
  ll v[maxm << 1] = {};
  ll qmax(int p) {
    ll res = 0;
    for (; p; p ^= p & -p) res = max(res, v[p]);
    return res;
  }
  void modify(int p, ll nv) {
    for (; p < (maxm << 1); p += p & -p) v[p] = max(v[p], nv);
  }
} tree;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) a[i].get();
  sort(cpy, cpy + cl);
  for (int i = 0; i < n; ++i) a[i].rem();
  sort(a, a + n, cmp);
  ll res = 0;
  for (int i = 0; i < n; ++i) {
    ll r = tree.qmax(a[i].ou - 1);
    tree.modify(a[i].in, r + a[i].h);
    res = max(res, r + a[i].h);
  }
  cout << res << '\n';
}
