w, h, n = gets.split.map(&:to_i)
a = (1..n).map { gets.split.map(&:to_i) }.sort_by(&:max)
i = j = 0
until a.empty?
    y, x = a.pop
    next if i >= y or j >= x
    if y < x
        i = y
    else
        j = x
    end
end
p i + j
