n = gets.to_i

ar = Array.new(100010, 0)

n.times do
    inp = gets.chomp.split
    a = inp[0].to_i
    b = inp[1].to_i
    ar[a] = ar[a] + 1
    ar[b+1] = ar[b+1] - 1
end

100009.times do |i|
    ar[i] = ar[i-1] + ar[i]
end

max = 1
100009.times do |i|
    if(ar[i] >= i-1)
        max = i
    end
end

puts max - 1