#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 100005;
struct ring {
  int a, b;
  long long h;
  bool operator<(const ring &x) const { return b < x.b; }
} r[maxn], neo_r[maxn];
long long f[maxn];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> r[i].a >> r[i].b >> r[i].h;
  if (n == 1) {
    cout << r[1].h << endl;
    return 0;
  }
  sort(r + 1, r + 1 + n);
  int neo_n = 0, min_a = r[1].a, tot_h = r[1].h;
  for (int i = 2, l = 1;; ++i) {
    if (i == n) {
      if (r[i].b != r[l].b) {
        neo_r[++neo_n] = (ring){min_a, r[l].b, tot_h};
        neo_r[++neo_n] = r[i];
      } else
        neo_r[++neo_n] = (ring){min(min_a, r[i].a), r[l].b, tot_h + r[i].h};
      break;
    }
    if (r[i].b != r[l].b) {
      neo_r[++neo_n] = (ring){min_a, r[l].b, tot_h};
      l = i, min_a = r[i].a, tot_h = r[i].h;
    } else {
      min_a = min(min_a, r[i].a);
      tot_h += r[i].h;
    }
  }
  long long ans = 0;
  stack<int> opt;
  for (int i = neo_n; i; --i) {
    while (!opt.empty() && neo_r[opt.top()].a >= neo_r[i].b) opt.pop();
    if (!opt.empty()) f[i] = f[opt.top()];
    f[i] += neo_r[i].h;
    opt.push(i);
    ans = max(f[i], ans);
  }
  cout << ans << endl;
  return 0;
}
