#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 411031;
int n, a[N], b[N], h[N];
vector<int> vals;
vector<pair<int, int> > order;
map<int, int> maps;
long long ans;
long long t[N * 4];
vector<int> compress(vector<int> v) {
  sort(v.begin(), v.end());
  vector<int> ret;
  for (int i = 0; i < v.size(); i++) {
    if (i == 0 || v[i] != v[i - 1]) ret.push_back(v[i]);
  }
  return ret;
}
long long get(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (tl == l && tr == r) return t[v];
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  return max(get(v * 2, tl, sdfjahlfasfh, l, min(r, sdfjahlfasfh)),
             get(v * 2 + 1, sdfjahlfasfh + 1, tr, max(sdfjahlfasfh + 1, l), r));
}
void update(int v, int tl, int tr, int ps, long long val) {
  if (tl == tr) {
    t[v] = max(t[v], val);
    return;
  }
  int sdfjahlfasfh = tl + tr;
  sdfjahlfasfh /= 2;
  if (ps <= sdfjahlfasfh)
    update(v * 2, tl, sdfjahlfasfh, ps, val);
  else
    update(v * 2 + 1, sdfjahlfasfh + 1, tr, ps, val);
  t[v] = max(t[v * 2], t[v * 2 + 1]);
}
bool cmp2(int v1, int v2) {
  if (b[v1] != b[v2]) return b[v1] > b[v2];
  return a[v1] > a[v2];
}
bool cmp(pair<int, int> p1, pair<int, int> p2) {
  return cmp2(p1.second, p2.second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i] >> h[i];
    vals.push_back(a[i]);
    vals.push_back(b[i]);
  }
  vals = compress(vals);
  for (int i = 0; i < vals.size(); i++) {
    maps[vals[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    a[i] = maps[a[i]];
    b[i] = maps[b[i]];
    order.push_back(make_pair(b[i], i));
  }
  sort(order.begin(), order.end(), cmp);
  for (int i = 0; i < order.size(); i++) {
    int id = order[i].second;
    long long here = get(1, 0, vals.size() - 1, 0, b[id] - 1);
    ans = max(ans, here + h[id]);
    update(1, 0, vals.size() - 1, a[id], here + h[id]);
  }
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
