#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1e18,mod=1e9+7;
ll fact[1000000],ifact[1000000];
ll power (ll a,ll b){

    ll res=1;
    while(b){
        if(b&1)
        res=(res*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return res;

}
ll ncr(ll n,ll r){

    if(n<=r)
    return 1;
    ll res=1;
    res=fact[n];
    res=(res*ifact[n-r])%mod;
    res=(res*ifact[r])%mod;

    return res;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif

        ll n;cin>>n;
        ll arr[3][n];
        for(ll i=0;i<n;i++)
        cin>>arr[0][i]>>arr[1][i]>>arr[2][i];

        ll mi=inf;
        for(ll i=0;i<n;i++){
            if(arr[2][i]-arr[0][i]>0)
            mi=min(mi,arr[1][i]);
        }
        if(mi==inf)
        cout<<-1<<endl;
        else
        cout<<mi;


}

#include <iostream>
using namespace std;
int main() {                                         
int n,y,z,w,ab;
cin>>n;
cin>>y>>z>>w;
if(w>y) ab=z;
else ab=0;
for(int i=1;i<n;i++){
    int A,P,X;                 
    cin>>A>>P>>X;               
    if(X>A){                   
        if(ab>P) ab=P;
        if(ab==0)ab=P;
    }   
}
if(ab>0)cout<<ab;
else cout<<-1;
}