// Arup Guha
// 3/26/2024
// Solution to CSES Problem: Projects
// https://cses.fi/problemset/task/1140
// Note: Will post a better solution (student will write) that better utilizes C++ features soon.

using namespace std;

#include <bits/stdc++.h>

int binsearch(vector<vector<int>>& jobs, int idx);

int main() {

    // Number of jobs.
    int n;
    cin >> n;

    vector<vector<int>> jobs;
    vector<int> tmp{-1,-1,0};
    jobs.push_back(tmp);

    // Read in jobs, store as [end, start, money].
    for (int i=0; i<n; i++) {
        int s, e, money;
        cin >> s >> e >> money;
        vector<int> obj;
        obj.push_back(e);
        obj.push_back(s);
        obj.push_back(money);
        jobs.push_back(obj);
    }

    // Sort by end time.
    sort(jobs.begin(), jobs.end());

    vector<long> dp(n+1);
    dp[0] = 0;


    // 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];

        // Returns the max index of a job that completes before job i finishes.
        int prevIndex = binsearch(jobs, i);

        // If I take this job, the most I can add to it is the best score from prevIndex.
        long alt = dp[prevIndex] + jobs[i][2];

        // Update if necessary.
        dp[i] = max(dp[i], alt);
    }

    // Ta da!
    cout << dp[n] << endl;

    return 0;
}

// Returns the max value i such that job i ends before job idx begins.
int binsearch(vector<vector<int>>& jobs, int idx) {

    int low = 0, high = idx-1;

    // Run a usual binary search on the key, jobs[0].
    while (low < high) {

        int mid = (low+high+1)/2;

        // This is the case where mid starts at or AFTER idx ends.
        if (jobs[mid][0] >= jobs[idx][1])
            high = mid-1;

        // The real answer is at least as big as mid.
        else
            low = mid;
    }

    return low;
}
