'''
	@judge CodeForces
	@id 479C
	@name Exams

	@tag Sortings, Greedy
'''
from sys import stdin

def solve(ls):
	ans = ls[0][1]
	for (a, b) in ls:
		ans = b if ans <= b else a
	return ans

n     = int(input())
exams = list(tuple(map(int, line.split())) for line in stdin.readlines())
res   = solve(sorted(exams, key = lambda p: p[0] * 1000000000 + p[1]))

print(res)
b5ccac1ebd4879b678598353f0a3d835a21771ca
<mask token>


def solve(ls):
    ans = ls[0][1]
    for a, b in ls:
        ans = b if ans <= b else a
    return ans


<mask token>

<mask token>


def solve(ls):
    ans = ls[0][1]
    for a, b in ls:
        ans = b if ans <= b else a
    return ans


<mask token>
print(res)

<mask token>


def solve(ls):
    ans = ls[0][1]
    for a, b in ls:
        ans = b if ans <= b else a
    return ans


n = int(input())
exams = list(tuple(map(int, line.split())) for line in stdin.readlines())
res = solve(sorted(exams, key=lambda p: p[0] * 1000000000 + p[1]))
print(res)

<mask token>
from sys import stdin


def solve(ls):
    ans = ls[0][1]
    for a, b in ls:
        ans = b if ans <= b else a
    return ans


n = int(input())
exams = list(tuple(map(int, line.split())) for line in stdin.readlines())
res = solve(sorted(exams, key=lambda p: p[0] * 1000000000 + p[1]))
print(res)

'''
	@judge CodeForces
	@id 479C
	@name Exams

	@tag Sortings, Greedy
'''
from sys import stdin

def solve(ls):
	ans = ls[0][1]
	for (a, b) in ls:
		ans = b if ans <= b else a
	return ans

n     = int(input())
exams = list(tuple(map(int, line.split())) for line in stdin.readlines())
res   = solve(sorted(exams, key = lambda p: p[0] * 1000000000 + p[1]))

print(res)