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

int main() {
  int n;
  cin >> n;

  vector<long long> a(n), p(n), x(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i) >> p.at(i) >> x.at(i);
  }

  bool check = false;
  long long ans;
  for (int i = 0; i < n; i++) {
    if (a.at(i) < x.at(i)) {
      check = true;
      ans = p.at(i);
      break;
    }
  }
  if (check) {
    for (int i = 0; i < n; i++) {
      if (a.at(i) < x.at(i)) {
        ans = min(ans, p.at(i));
      }
    }
  }
  else {
    ans = -1;
  }

  cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

#define ll              long long int
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; 
#define endl            '\n'
#define pb              push_back
#define vll             vector<ll> 
#define f(i,x,y)        for(i=x;i<y;i++)
#define INF             LLONG_MAX
#define s(x)            sort(x.begin(),x.end())
#define all(v)          v.begin(),v.end()
#define p2(n,x)         cout << fixed << setprecision(x) <<n<<endl; 
#define pll             pair<ll,ll> 
#define mll             map<ll,ll>
#define ff              first
#define ss              second
#define blt(x)          __builtin_popcount(x)

void solve()
{
    ll i,j,k,n;
    cin>>n;
    vll a(n),p(n),x(n);
    vll v;
    f(i,0,n)
    {
        cin>>a[i]>>p[i]>>x[i];
        x[i]-=a[i];
        if(x[i]>0)
            v.pb(p[i]);
    }
    s(v);
    if(!v.size())
        cout<<-1;
    else
        cout<<v[0];



    
}

int main()
{
   

    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll t = 1;
    while(t--) {
        solve();    
    }
    return 0;
}