   #include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
  
 typedef vector<int> vi;
 typedef vector<ll> vl;
 typedef vector<vi> vvi;
 typedef set<int> si;
 typedef set<ll> sl;
 typedef queue<int> qi;
 typedef queue<ll> ql;
 typedef stack<int> sti;
 typedef deque<int> dqi;
 typedef priority_queue<int> pqi;
 typedef priority_queue<ll> pql;
 typedef deque<ll> dql;
 typedef vector<vl> vvl;
 typedef pair<int,int> pii;
 typedef pair<double, double> pdd;
 typedef pair<ll, ll> pll;
 typedef vector<pii> vii;
 typedef vector<pll> vll;
 typedef double dl;
                    
 #define PB push_back
 
 #define F first
 #define S second
 #define MP make_pair
 #define el  '\n'
 #define sl(x) (int)x.length()
 #define all(a) (a).begin(),(a).end()
 #define sz(x) (int)x.size()
 #define mid(l,r) ((r+l)/2)
 #define left(node) (node*2)
 #define right(node) (node*2+1)
 #define mx_int_prime 999999937
#define loop(i,n)        for(int i=0;i<n;i++) 

 const double PI = acos(-1);
 const double eps = 1e-9;
 const int inf = 2000000000;
 const ll infLL = 9000000000000000000;
 #define MOD 1000000007
 #define in(n)  ll n;cin>>n;         
 #define mem(a,b) memset(a, b, sizeof(a) )
 #define gcd(a,b) __gcd(a,b)
 #define sqr(a) ((a) * (a))
 #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 #define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield);
 typedef vector<int>::iterator vit;
 typedef set<int>::iterator sit;
 int dx[] = {0, 0, +1, -1};
 int dy[] = {+1, -1, 0, 0};

 void solve(){
        


    }
  int main(){
    in(n);
    int ans=MOD;
    bool pk=0;
    while(n--){
        in(a);
        in(b);
        in(c);
        int ok=0;
        if(a<c){
          pk=1;
          ok=b;
        ans=min(ok,ans);
        }
    }
    if(pk==0)cout<<"-1"<<el;
    else
    cout<<ans<<el;
      
    }
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long llp;
#define mod 1000000007
#define deb(x) cerr << '\t' << "[" << #x << ": "<< x << "]\n";
#define f first
#define s second
#define pb push_back
/*
numeric_limits<llp>::max();
*/
void solution(/*ll tc = 0*/);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    llp tc = 1;
    //cin >> tc;
    for (llp t = 0; t < tc; ++t) solution(/*t*/);
    return 0;
}

struct ps{
	ll a, p, x;
};
bool fx(struct ps a, struct ps b) {
	return (a.p < b.p);
}
void solution(/*ll tc = 0*/) {
	int n;
	cin >> n;
	vector<ps> arr(n);
	for(int i = 0; i < n; ++i) {
		cin >> arr[i].a >> arr[i].p >> arr[i].x;
	}
	sort(arr.begin(), arr.end(), fx);
	//ll ans = (ll)1e9;
	bool canwe = 0;
	for(int i = 0; i < n; ++i) {
		if(arr[i].x > arr[i].a) {
			cout << arr[i].p << '\n';
			canwe = 1;
			break;
			//ans = min(ans, arr[i].p);
		}
	}
	if(!canwe) cout << "-1\n";
//	cout << ans << '\n';
}








