// Arup Guha
// 3/26/2024
// Solution to CSES Problem: Projects
// https://cses.fi/problemset/task/1140
// Modified by Jason Helman

#include <bits/stdc++.h>

using namespace std;

int main() {

    // Number of jobs.
    int n;
    cin >> n;

    // start all with [end=-1, start=-1, $=0]
    vector<vector<int>> jobs(n+1, {-1, -1, 0});

    // Read in jobs, store as [end, start, money].
    // jobs[0] is for the edge case
    for (int i=1; i<=n; i++)
        cin >> jobs[i][1] >> jobs[i][0] >> jobs[i][2];

    // Sort by end time.
    sort(jobs.begin(), jobs.end());

    vector<long long int> dp(n+1);

    // Get best result upto each ending job.
    for (int i=1; i<=n; i++) {

        // This is without job i-1.
        dp[i] = dp[i-1];

        // Gets an iterator to the first job in range [0, i) where its end date is *not* < the current job's start.  (Points to one past the max index.)
        auto onePastMax = lower_bound(jobs.begin(), jobs.begin() + i, vector<int>{jobs[i][1]});

        // The desired index is one before.
        int prevIndex =  onePastMax - jobs.begin() - 1;

        // If I take this job, the most I can add to it is the best score from prevIndex.
        long long int alt = dp[prevIndex] + jobs[i][2];

        // Update if necessary.
        dp[i] = max(dp[i], alt);
    }

    // Ta da!
    cout << dp[n] << endl;

    return 0;
}

