#include <bits/stdc++.h>
#include <string.h>
#include <map>
#include <stack>
#include <queue>
using namespace std;
const int N=5e4+10;
const int M=4*N;
int n;
int d[N],q[N];
int head[M],w[M],ne[M],e[M],tot;
bool st[N];
void add(int a,int b,int c){
e[tot]=b,w[tot]=c,ne[tot]=head[a],head[a]=tot++;
}
void spfa(){ // 模拟队列的spfa
memset(d, -0x3f , sizeof d);
int hh=0,tt=0;
d[0]=0;
st[0]=true;
q[tt++]=0;
while(hh!=tt){
int temp=q[hh++];
if(hh==N) hh=0;
st[temp]=false;
for(int i=head[temp] ; i!=-1 ; i=ne[i]){
int j=e[i];
if( d[j] < d[temp] + w[i]){
d[j] = d[temp] + w[i];
if(!st[j]){
st[j]=true;
q[tt++]=j;
if(tt==N) tt=0;
}
}
}
}
}
int main(){
// 设d[k]表示 0 ~k 种最少有多少数选
// a<= x <= b =》 类似前缀和 d【b】-d【a-1】>=c (边:a-1 , d , c)
// 当然有相对关系是不能求出最小值的,需要增加一些形如xi >=c 或者额外的关系
// s[k] - s[k-1] >=0 (边:k-1,k,0)
// s[k] - s[k-1] <=1 ==> s[k-1] - s[k] >= -1; (边:k, k-1, -1)
memset(head , -1 ,sizeof head);
cin>>n;
for(int i=1;i<N;i++){
add(i,i-1,-1);
add(i-1,i,0);
}
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
a++,b++;
add(a-1,b,c);
}
spfa();
cout<<d[50001]<<endl;
system("pause");
return 0;
}