#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>



using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
/*
 execution in cmd for windows: g++ p1.cpp -op1


  p1

  execution in terminal for linux: g++ p1.cpp


  ./a.out

*/
typedef long double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 998244353;
const ll modulus = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1000000007;
#define pi 3.14159265
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)
#define cs1 ll t;t=1;while(t--)
#define input(v) for(i=0;i<v.size();i++) cin>>v[i];
#define output(v) for(i=0;i<v.size();i++) cout<<v[i]<<" ";
#define dbg(n) cout<<"[ "<<n<<" ]" nl;

int main()
{
    io;
    //////////////////////////////////

    cs1 {
        ll i, j, s = 0, c, k = 0, q = 0, m = 0, e = 1, f = -1, x, y, ans = INF, p = 0, r, a, b, d, len, ct = 0,n;
        cin>>n;
        vll va(n),vp(n),vx(n),v;
        for(i=0;i<n;i++) {
            cin >> va[i] >> vp[i] >> vx[i];
            if(vx[i]>va[i]) v.pb(vp[i]);
        }
        if(v.size()==0) cout<<"-1";
        else{
            fsort(v);cout<<v[0] ;
        }

    }
    //////////////////////////////////
    // cer;


}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll ans = -1;
  for (int i = 0; i < N; ++i) {
    ll A, P, X;
    cin >> A >> P >> X;

    if (X - A > 0) {
      if (ans < 0) {
        ans = P;
      } else {
        ans = min(ans, P);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
