#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(x) (memset(x,0,sizeof(x)))
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}



// head
 int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int __=1;
    //cin>>__;
    while(__--)
    {
        int n;
        cin>>n;
        int a,c,s;
                int num=1e9+5;
        rep(i,0,n)
        {
            cin>>a>>c>>s;
            if(a<s)
                num=min(c,num);
        }
        if(num>1e9)
            cout<<"-1";
        else
        cout<<num<<endl;
    }

}

#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
typedef long long ll;
#define int long long
#define endl "\n"
#define forp(i, x, t) for (int i = x; i < t; i++)
#define forn(i, t) for (int i = t; i >= 0; i--)
#define deb(x) cout << #x << " = " << x << endl
const int mod = 1e9 + 7;

using namespace std;

void solve(){
    

}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // int t = 1;
    // cin >> t;
    // while (t--){
    //     solve();
    // }

    int n;
    cin>>n;
    int time = 0;
    int ans = INT32_MAX;
    while (n--){
        int a,p,x;
        cin>>a>>p>>x;
        time += a;
        x -= a;
        if (x > 0){
            ans = min(ans, p);
        }


    }
    if (ans == INT32_MAX) cout << -1;
    else cout<<ans;
    return 0;
}