5)
#include<bits/stdc++.h>
using namespace std;
pair <int, int> a[5000];
int main(){
	int n;
	cin >> n;
	int b = 0;
	int num = 1;
	for (int i = 0; i < n; i++){
		cin >> a[i].second;
		cin >> a[i].first;
		if (a[i].second >= b){
			b = a[i].second;
		}
	}
	sort(a, a + n);
	for (int i = 1; i < n; i++){
		if (a[i].second >= a[i - 1].second){
			num++;
		}
	}
	if (num == n){
		cout << a[n - 1].first;
	}
	else{
		cout << b;
	}
	
}