require 'pp'

h, w, m = gets.split.map(&:to_i)
rows = Array.new(w,0)
cols = Array.new(h,0)
memo = Array.new(h)
h.times do |i|
    memo[i] = Array.new(w, 0)
end

m.times do |i|
    h_n, w_n = gets.split.map(&:to_i)

    rows[w_n-1] += 1
    cols[h_n-1] += 1
    memo[h_n-1][w_n-1] = 1
end

o_rows = Array.new(w, 0)
rows.each_with_index do |r, i|
    o_rows[i] = [r, i]
end
o_rows.sort!.reverse!

o_cols = Array.new(h, 0)
cols.each_with_index do |c, i|
    o_cols[i] = [c, i]
end
o_cols.sort!.reverse!

#pp o_rows
#pp o_cols
#pp "====="

max = 0
queue = []
queue << [0, 0]

while queue.empty?.!
    r_i, c_i = queue.shift
    c1, x = o_rows[r_i]
    c2, y = o_cols[c_i]

    #pp c1
    #pp c2
    #pp "(#{y}, #{x})"
    #pp memo[y][x]
    if c1 + c2 + 1 <= max
        break
    end

    if memo[y][x] == 0
        max = c1 + c2
        break
    end

    max = [max, c1 + c2 - 1].max

    if r_i + 1 < w
        queue << [r_i+1, c_i]
    end
    if c_i + 1 < h
        queue << [r_i, c_i+1]
    end

    #pp queue
    #gets
end

puts max
