H,W,M = gets.split.map(&:to_i)
A = readlines.map {|s| s.split.map(&:to_i) }

ob = Array.new(H+1) { [] }
bh = Array.new(H+1, 0)
bw = Array.new(W+1, 0)
mh = 0
mw = 0
A.each do |y,x|
  ob[y] << x
  bh[y] += 1
  bw[x] += 1
  mh = bh[y] if mh < bh[y]
  mw = bw[x] if mw < bw[x]
end

a = bh.each_with_index.inject([]) {|r,(n,i)| n == mh ? r << i : r }
b = bw.each_with_index.inject([]) {|r,(n,i)| n == mw ? r << i : r }
puts mh + mw + (a.all? {|y| (b - ob[y]).empty? } ? -1 : 0)