#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long long N = 1e6;
struct data {
  long long val;
};
data seg_tree[8 * N];
long long n;
long long a_mx[2 * N + 100];
long long dp[N];
vector<pair<long long, pair<long long, long long> > > arr;
map<long long, long long> ac;
data combine(data l, data r) {
  data res;
  res.val = max(l.val, r.val);
  return res;
}
void build(long long v, long long l, long long r) {
  if (l == r) {
    seg_tree[v].val = 0;
    return;
  }
  long long m = (l + r) / 2;
  build(2 * v, l, m);
  build(2 * v + 1, m + 1, r);
  seg_tree[v] = combine(seg_tree[2 * v], seg_tree[2 * v + 1]);
  return;
}
void update(long long v, long long l, long long r, long long pos,
            long long new_val) {
  if (l == r) {
    seg_tree[v].val = new_val;
    return;
  }
  long long m = (l + r) / 2;
  if (pos <= m) {
    update(2 * v, l, m, pos, new_val);
  } else {
    update(2 * v + 1, m + 1, r, pos, new_val);
  }
  seg_tree[v] = combine(seg_tree[2 * v], seg_tree[2 * v + 1]);
}
data query(long long v, long long l, long long r, long long ql, long long qr) {
  if (ql > qr) {
    data ans;
    ans.val = 0;
    return ans;
  }
  if (ql == l and qr == r) {
    return seg_tree[v];
  }
  long long m = (l + r) / 2;
  return combine(query(2 * v, l, m, ql, min(qr, m)),
                 query(2 * v + 1, m + 1, r, max(ql, m + 1), qr));
}
bool cmp(pair<long long, pair<long long, long long> >& a,
         pair<long long, pair<long long, long long> >& b) {
  if (a.first != b.first) {
    return a.first > b.first;
  } else {
    return a.second.first > b.second.first;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  set<long long> a_val;
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    a_val.insert(a);
    a_val.insert(b - 1);
    arr.push_back(make_pair(b, make_pair(a, c)));
  }
  sort(arr.begin(), arr.end(), cmp);
  long long curr = 1;
  for (auto i : a_val) {
    ac[i] = curr;
    curr++;
  }
  build(1, 0, 2 * N);
  curr = 0;
  long long ans = -1;
  for (auto i : arr) {
    data node = query(1, 0, 2 * N, 1, ac[i.first - 1]);
    dp[curr] = node.val + i.second.second;
    ans = max(ans, dp[curr]);
    if (a_mx[ac[i.second.first]] < dp[curr]) {
      a_mx[ac[i.second.first]] = dp[curr];
      update(1, 0, 2 * N, ac[i.second.first], dp[curr]);
    }
    curr++;
  }
  cout << ans << "\n";
}
