#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
inline long long gcd(long long a, long long b) {
  a = ((a) < 0 ? -(a) : (a));
  b = ((b) < 0 ? -(b) : (b));
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
long long ext_gcd(long long A, long long B, long long *X, long long *Y) {
  long long x2, y2, x1, y1, x, y, r2, r1, q, r;
  x2 = 1;
  y2 = 0;
  x1 = 0;
  y1 = 1;
  for (r2 = A, r1 = B; r1 != 0;
       r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y) {
    q = r2 / r1;
    r = r2 % r1;
    x = x2 - (q * x1);
    y = y2 - (q * y1);
  }
  *X = x2;
  *Y = y2;
  return r2;
}
inline long long modInv(long long a, long long m) {
  long long x, y;
  ext_gcd(a, m, &x, &y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
inline long long power(long long a, long long p) {
  long long res = 1, x = a;
  while (p) {
    if (p & 1) res = (res * x);
    x = (x * x);
    p >>= 1;
  }
  return res;
}
inline long long bigmod(long long a, long long p, long long m) {
  long long res = 1 % m, x = a % m;
  while (p) {
    if (p & 1) res = (res * x) % m;
    x = (x * x) % m;
    p >>= 1;
  }
  return res;
}
inline int STRLEN(char *s) {
  int p = 0;
  while (s[p]) p++;
  return p;
}
inline long long SQRT(long long a) {
  long long v = sqrt(a);
  if (((v) * (v)) == a)
    return v;
  else if (((v + 1) * (v + 1)) == a)
    return v + 1;
  else if (((v + 2) * (v + 2)) == a)
    return v + 2;
  else
    return -1;
}
const int inf = (1 << 29);
const double pi = 2 * acos(0.0);
const double eps = 1e-9;
struct vert {
  long long val;
};
vert T[200050 * 4];
void ut(int c, int s, int e, int u, int v, long long val) {
  if (e < u || s > v) return;
  if (s >= u && e <= v) {
    T[c].val = val;
    return;
  }
  int L = c * 2, R = c * 2 + 1, M = (s + e) / 2;
  ut(L, s, M, u, v, val);
  ut(R, M + 1, e, u, v, val);
  T[c].val = max(T[L].val, T[R].val);
}
long long qt(int c, int s, int e, int u, int v) {
  if (e < u || s > v) return 0;
  if (s >= u && e <= v) return T[c].val;
  int L = c * 2, R = c * 2 + 1, M = (s + e) / 2;
  long long v1 = qt(L, s, M, u, v);
  long long v2 = qt(R, M + 1, e, u, v);
  return max(v1, v2);
}
struct ring {
  int R, r, H;
};
bool cmp(ring a, ring b) { return (a.R > b.R); }
int N, NN = 1;
ring A[200050];
map<int, int> Map;
vector<int> List;
int opt[200050];
void compress() {
  sort((List).begin(), (List).end());
  for (int i = 0; i < List.size(); i++) {
    int v = List[i];
    if (Map[v] == 0) Map[v] = NN++;
  }
  for (int i = 0; i < 200050; i++) opt[i] = inf;
  for (int i = 0; i < N; i++) {
    A[i].r = Map[A[i].r];
    A[i].R = Map[A[i].R];
    opt[A[i].R] = min(opt[A[i].R], A[i].r);
  }
}
void solve() {
  sort(A, A + N, cmp);
  long long res = 0;
  for (int i = 0; i < N; i++) {
    long long mx = qt(1, 1, NN, 1, A[i].R - 1) + A[i].H;
    res = max(res, mx);
    int v = opt[A[i].R];
    ut(1, 1, NN, v, v, mx);
  }
  printf("%lld\n", res);
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &A[i].r, &A[i].R, &A[i].H);
    List.push_back(A[i].R);
    List.push_back(A[i].r);
  }
  compress();
  solve();
  return 0;
}
