#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long N, A, P, X, s=0, a[100000];
    cin>>N;

    for(int i=0; i<N; i++)
    {
        cin>>A>>P>>X;
        if(X>A)
        {
            a[i]=P;
        }
        else
        {
            a[i]=0;
        }
    }

    for(int i=0; i<N; i++)
    {
        s=s+a[i];
    }

    if(s==0)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        sort(a, a+N);
        for(int i=0; i<N; i++)
        {
            if(a[i]>0)
            {
                cout<<a[i]<<endl;
                i=N;
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int     
int main(){
    int n;
    cin>>n;
    ll a[n];
    ll p[n];
    ll x[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>p[i]>>x[i];
    }
    ll ans = INT_MAX;
    for(int i=0;i<n;i++){
        int diff = x[i]-a[i];
        if(diff>0){
            ans = min(ans,p[i]);
        }
    }
    if(ans==INT_MAX)ans = -1;
    cout<<ans<<endl;
     return 0;
}