require 'pp'
require 'set'

###################

#inputType = :singleLine
# inputType = :2Lines
inputType = :nLines
  
def main(query)
  h,w,m = query.shift

  th = {}
  tw = {}

  query = query.to_set
  
  query.each { | l |
    bh,bw = tois(l.split(" "))
    th[bh] = (th[bh] || 0) + 1
    tw[bw] = (tw[bw] || 0) + 1
  }

  sum = 0

  ppp "th=",th
  ppp "tw=",tw
  ppp "query=",query
  
  hs = th.keys.sort { | a,b | th[b] <=> th[a] }
  maxh = th[hs[0]]
  hs1 = hs.select { | a | th[a] == maxh }
  
  ws = tw.keys.sort { | a,b | tw[b] <=> tw[a] }
  maxw = tw[ws[0]]
  ws1 = ws.select { | a | tw[a] == maxw }

  hs1.each { | h |
    ws1.each { | w |
      k = h.to_s + " " + w.to_s
      p k
      if (! query.include?(k)) then
        return [(maxh + maxw)]
      end
    }
  }
  return [(maxh + maxw - 1)]
  
end

###################

TEST=false

def tois(l)
  l.map { | x | x.to_i}
end

def ppp(msg, val)
  if (TEST) then
    print msg
    pp val
  end
end

target = nil
if (ARGV.size == 0) then
  f = STDIN
end
if (ARGV.size > 0) then
  f = open(ARGV[0])
end
if (ARGV.size > 1) then
  target = ARGV[1].to_i
end

t = 1
ng = []
while true
  query = []
  if (inputType == :singleLine) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
  elsif (inputType == :l2Lines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
    b = f.gets.chomp
    query.push b
  elsif (inputType == :l3Lines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a
    b = f.gets.chomp
    query.push b
    c = f.gets.chomp
    query.push c
  elsif (inputType == :nLines) then
    a = f.gets
    if ! a then
      exit
    end
    a.chomp!
    query.push a    

    n = a.split(" ")[2].to_i

    n.times { | i |
      query.push f.gets.chomp
    }    
  end
  
  aa = f.gets
  if ! aa then
    r = main(query) 
    r.each { | x | puts x }
    exit
  elsif ( aa.chomp == "---") then
    oks = []
    while true
      s = f.gets.chomp
      if (s == "===") then
        break
      end
      oks.push s
    end

    if (target == nil || t == target) then
      if target then
        TEST = true
      end

      puts "--- " + t.to_s + " ---"
      r = main(query)    

      if r.join('\n') == oks.join('\n') then
        puts "RESULT:"
        r.each { | x | puts x }
        puts "OK"
      else
        puts "RESULT:NG"
        r.each { | x | puts x }
        puts "NG!!!!!!!!!"
        ng.push t
      end
    end
  end
  t = t + 1
end
puts "---"
puts "NG targes = " + ng.to_s
