#include <stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	int A[N],P[N],X[N];
	int a,b,c;
	long long d=1000000000001;
	int e=0;
	for(a=0;a<N;a++) {
		scanf("%d %d %d\n",&A[a],&P[a],&X[a]);
	}
	for(b=0;b<N;b++) {
		if(X[b]-A[b]>0) {
			if(d>P[b]) {
				d=P[b];
			}
		}
		else e++;
	}
	
	if(e!=N) printf("%lld",d);
	else printf("-1");
	
	return 0;
}
		
	
//CODED BY SUMIT KUMAR PRAJAPATI
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;

#define PI 3.1415926535897932384626
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define watch(x) cerr<<#x<<" = "<<x<<'\n'
#define rep(i,n) for(ll i=0;i<n;i++)
#define repe(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n'
#define curtime chrono::high_resolution_clock::now()
#define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count()

const int INF=1e9;
const int MX=1e5+5;
const int MD=1e9+7;
const int MDL=99824453;
auto time0 = curtime;
 
 
 
 
 
 
void solve(){
  
    int N;
    cin>>N;
    int A[N+1],P[N+1],X[N+1];
    int ans=MD;
    repe(i,N){
        cin>>A[i]>>P[i]>>X[i];
        if(X[i]-(A[i]-0.5+1)>0)
            ans=min(ans,P[i]);
        //t a-=(t-0.5+1)
    }
    if(ans==MD)
        cout<<"-1\n";
    else
        cout<<ans<<'\n';
 
} 
 
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    srand(time(0)); 
    time0 = curtime;

    ll t=1;
    //cin>>t;
    repe(tt,t){
        //cout<<"Case #"<<tt<<": ";
        solve();
    }
    
    cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n";
    return 0;
 
}