#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (int)1e9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
//
#define FOR(i, a, b, in) for (int i=a ; i<(b) ; i+=in)
#define RFOR(i, a, b, in) for (int i=a-1 ; i>=(b) ; i-=in)
#define REP(i, a, b) FOR(i, a, b, 1)
#define RREP(i, a, b) RFOR(i, a, b, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define all(cont) cont.begin(), cont.end()


void solve () {
	int ans = 1e9;
	bool ok = 0;
	int n;
	cin >> n;
	REP (i, 0, n) {
		int a, p, x;
		cin >> a >> p >>x;
		if (a < x) {
			ans = min(ans, p);
			ok = true;
		}
	}
	if (!ok) ans = -1;
	
	cout << ans << "\n";
}

int main () 
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	
	return 0;
}
//$ sudo g++ -o name name.cpp
//$ ./name


#include<bits/stdc++.h>
using namespace std;
int main(){
int n,x=1e8,y=1e8,x1,y1,i,s,p,q,a,b,c=1e8,d=1e8;
cin>>n;
int arr[n][2];
 for(i=0;i<n;i++){
 	cin>>arr[i][0]>>arr[i][1];
 	if(arr[i][0]<x){
 		x=arr[i][0];
 	  x1=i;}
 	 if(arr[i][1]<y){
 	 	y=arr[i][1];
 	 	y1=i;}}
 	 if(x1==y1){
 	 	p = x+y;
 	 	for(i=0;i<n;i++){
 	 		if(i!=x1){
 	 		c = min(c,arr[i][0]);}}
 	 	for(i=0;i<n;i++){
 	 		if(i!=y1){
 	 			d=min(d,arr[i][1]);}}
 	 				c=max(c,y);
 	 				d=max(d,x);
 	 			c=min(c,d);
 	 			c = min(c,p);
 	 			cout<<c;}
 	 	else{
 	 		p = max(x,y);
 	 		cout<<p;}

return 0;}