#include <bits/stdc++.h>
using namespace std;
struct treap {
  struct Node {
    int y;
    long long a, h, mx;
    Node *L, *R;
    Node(long long A, long long H) {
      L = R = NULL;
      a = A;
      h = mx = H;
      y = rand();
    }
  };
  typedef Node *Treap;
  Treap root;
  treap() { root = NULL; }
  void destruct(Treap T) {
    if (T == NULL) return;
    destruct(T->L);
    destruct(T->R);
    delete T;
  }
  ~treap() { destruct(root); }
  long long mx(Treap T) { return T == NULL ? 0 : T->mx; }
  void recalc(Treap T) { T->mx = max({T->h, mx(T->L), mx(T->R)}); }
  Treap merge(Treap L, Treap R) {
    if (L == NULL || R == NULL) return R == NULL ? L : R;
    if (L->y > R->y) {
      L->R = merge(L->R, R);
      recalc(L);
      return L;
    } else {
      R->L = merge(L, R->L);
      recalc(R);
      return R;
    }
  }
  pair<Treap, Treap> split(Treap T, long long key) {
    if (T == NULL) return pair<Treap, Treap>(NULL, NULL);
    if (T->a < key) {
      pair<Treap, Treap> tmp(split(T->R, key));
      T->R = tmp.first;
      recalc(T);
      return pair<Treap, Treap>(T, tmp.second);
    } else {
      pair<Treap, Treap> tmp(split(T->L, key));
      T->L = tmp.second;
      recalc(T);
      return pair<Treap, Treap>(tmp.first, T);
    }
  }
  long long best(long long b) {
    pair<Treap, Treap> tmp(split(root, b));
    long long res(mx(tmp.first));
    root = merge(tmp.first, tmp.second);
    return res;
  }
  void insert(long long a, long long h) {
    pair<Treap, Treap> tmp(split(root, a));
    root = merge(tmp.first, merge(new Node(a, h), tmp.second));
  }
  long long ans() { return mx(root); }
};
struct circle {
  long long a, b, h;
};
bool cmp(const circle &a, const circle &b) {
  if (a.b == b.b) return a.a > b.a;
  return a.b > b.b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  circle x[n];
  for (int i(0); i < n; ++i) cin >> x[i].a >> x[i].b >> x[i].h;
  sort(x, x + n, cmp);
  treap t;
  for (int i(0); i < n; ++i) t.insert(x[i].a, t.best(x[i].b) + x[i].h);
  cout << t.ans();
}
