#!/usr/bin/env python3
n = int(input())

# imos[k]: わたしがちょうどk人誘うときに来れる最大人数
imos = [0] * (10**5 + 2)
for _ in range(n):
    a, b = map(int, input().split())
    imos[a - 1] += 1
    imos[b] -= 1
for i in range(n):
    imos[i + 1] += imos[i]

ans = 0
for i in range(n + 1):
    if imos[i] >= i:
        ans = max(ans, i)
print(ans)

