CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline
import heapq
from collections import Counter

H,W,M = list(map(int, input().split()))
BH = [[0,i] for i in range(H)]
BW = [[0,i] for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = list(map(int, input().split()))
  h,w = h-1,w-1
  BH[h][0] += 1
  BW[w][0] += 1
  Bomb.add((h,w))
  
BH.sort(reverse=True)
BW.sort(reverse=True)
  
"""
print(BombC)
print(BH)
print(BW)
"""

h = []
ans = 0
nowh, noww = 0,0
i,j = 0,0
BHMAX, BWMAX = BH[i][0], BW[j][0]
heapq.heappush(h, (-BH[i][0] - BW[j][0], BH[i][1], BW[j][1], i,j))
while h:
  cost, nowh, noww,i,j = heapq.heappop(h)
  cost = -cost
  #print(cost,nowh,noww)
  if (nowh,noww) not in Bomb:
    ans = max(ans,cost)
    break
  else:
    ans = max(ans, cost-1)
    if i+1 < H and BH[i+1][0] == BHMAX:
      heapq.heappush(h, (-BH[i+1][0] - BW[j][0], BH[i+1][1], BW[j][1],i+1, j))
    if j+1 < W and BW[i+1][0] == BWMAX:
      heapq.heappush(h, (-BH[i][0] - BW[j+1][0], BH[i][1], BW[j+1][1],i, j+1))
      
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline

H,W,M = list(map(int, input().split()))
BH = [0 for i in range(H)]
BW = [0 for i in range(W)]
Bomb = set()
for _ in range(M):
  h,w = list(map(int, input().split()))
  h,w = h-1,w-1
  BH[h] += 1
  BW[w] += 1
  Bomb.add((h,w))
  
BHMAX = max(BH)
BWMAX = max(BW)
HS = set()
WS = set()
for i in range(H):
  if BH[i] == BHMAX:
    HS.add(i)
for i in range(W):
  if BW[i] == BWMAX:
    WS.add(i)
    
ans = 0
cnt = 0
for h,w in Bomb:
  if h in HS and w in WS:
    ans = max(ans, BHMAX + BWMAX - 1)
    cnt += 1

if cnt < len(HS) * len(WS):
  ans = BHMAX + BWMAX
print(ans)
# Original solution
H, W, M = list(map(int, input().split()))
bom = [list(map(int, input().split())) for _ in range(M)]

hBom = [0]*H
wBom = [0]*W

# 各行、各列の爆破対象をカウント
for h, w in bom:
    hBom[h-1] += 1
    wBom[w-1] += 1

# 爆破対象の最大数と最大になる行と列の番号を調べる
maxHBom = max(hBom)
maxWBom = max(wBom)
maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom]
maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom]

# 爆破対象が最大になる行と列の組み合わせについて、
# 爆弾を配置する場所が爆破対象であるかないかで場合分け
for h in maxHBomIndex:
    for w in maxWBomIndex:
        if [h+1, w+1] not in bom:
            print((maxHBom + maxWBom))
            exit()
else:
    print((maxHBom + maxWBom - 1))

# Optimized solution
H, W, M = list(map(int, input().split()))
boms = [tuple(map(int, input().split())) for _ in range(M)]
# boms = [list(map(int, input().split())) for _ in range(M)]

hBom = [0]*H
wBom = [0]*W

# 各行、各列の爆破対象をカウント
for h, w in boms:
    hBom[h-1] += 1
    wBom[w-1] += 1

# 爆破対象の最大数と最大になる行と列の番号を調べる
maxHBom = max(hBom)
maxWBom = max(wBom)
maxHBomIndex = [index for index, h in enumerate(hBom) if h == maxHBom]
maxWBomIndex = [index for index, w in enumerate(wBom) if w == maxWBom]

# 爆破対象が最大になる行と列の組み合わせについて、
# 爆弾を配置する場所が爆破対象であるかないかで場合分け
boms = set(boms)
for h in maxHBomIndex:
    for w in maxWBomIndex:
        if (h+1, w+1) not in boms:
            print((maxHBom + maxWBom))
            exit()
else:
    print((maxHBom + maxWBom - 1))
# Original solution
import sys
H,W,M=list(map(int, input().split()))
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=list(map(int, input().split()))
    h.append(hi)
    w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print((max(Hcount)+max(Wcount)))
            sys.exit()
print((max(Hcount)+max(Wcount)-1))

# Optimized solution
import sys
 
input = sys.stdin.readline
 
 
def main():
    H, W, M = list(map(int, input().split()))
    row = [0] * (H)
    col = [0] * (W)
    bomb = set()
    for _ in range(M):
        h, w = list(map(int, input().split()))
        bomb.add((h, w))
        row[h-1] += 1
        col[w-1] += 1
    row_max = max(row)
    row_index_list = [i for i, v in enumerate(row) if v == row_max]
    col_max = max(col)
    col_index_list = [i for i, v in enumerate(col) if v == col_max]
    ans = row_max + col_max - 1
    c = False
    for x in row_index_list:
        for y in col_index_list:
            if not (x + 1, y + 1) in bomb:
                c = True
                break
        if c:
            break
    if c:
        ans += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()
# Original solution
import sys
H,W,M=list(map(int, input().split()))
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=list(map(int, input().split()))
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
h_max=[i for i, v in enumerate(Hcount) if v == max(Hcount)]
w_max=[i for i, v in enumerate(Wcount) if v == max(Wcount)]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print((max(Hcount)+max(Wcount)))
            sys.exit()
print((max(Hcount)+max(Wcount)-1))

# Optimized solution
import sys
H,W,M=list(map(int, input().split()))
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=list(map(int, input().split()))
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
Hcountmax=max(Hcount)
Wcountmax=max(Wcount)
h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax]
w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print((max(Hcount)+max(Wcount)))
            sys.exit()
print((max(Hcount)+max(Wcount)-1))
# Original solution
import sys
H,W,M=list(map(int, input().split()))
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=list(map(int, input().split()))
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
Hcountmax=max(Hcount)
Wcountmax=max(Wcount)
h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax]
w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax]
#print(h_max,w_max)
for ii in range(len(h_max)):
    for jj in range(len(w_max)):
        if (h_max[ii]+1,w_max[jj]+1) not in B:
            print((max(Hcount)+max(Wcount)))
            sys.exit()
print((max(Hcount)+max(Wcount)-1))

# Optimized solution
import sys
H,W,M=list(map(int, input().split()))
h=[]
w=[]
Hcount=[0 for _ in range(H)]
Wcount=[0 for _ in range(W)]
B=set()

for i in range(M):
    hi,wi=list(map(int, input().split()))
    #h.append(hi)
    #w.append(wi)
    B.add((hi,wi))
    Hcount[hi-1]+=1
    Wcount[wi-1]+=1
Hcountmax=max(Hcount)
Wcountmax=max(Wcount)
h_max=[i for i, v in enumerate(Hcount) if v == Hcountmax]
w_max=[i for i, v in enumerate(Wcount) if v == Wcountmax]
#print(h_max,w_max)
for ii in h_max:
    for jj in w_max:
        if (ii+1,jj+1) not in B:
            print((max(Hcount)+max(Wcount)))
            sys.exit()
print((max(Hcount)+max(Wcount)-1))
# Original solution
# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
h, w, m = list(map(int, input().split()))

h_list = [0]*h
w_list = [0]*w

# h_w_list = [[0 for j in range(w)] for i in range(h)]
h_w_list = []

for zzz in range(m):
  # print("---")
  bom_h, bom_w = list(map(int, input().split()))
  # print(bom_h, bom_w)
  h_list[bom_h-1] += 1
  w_list[bom_w-1] += 1

  # h_w_list[bom_h-1][bom_w-1] = 1
  h_w_list.append([bom_h, bom_w])

mh = max(h_list)
mw = max(w_list)
h_max_indexs = [i for i, v in enumerate(h_list) if v == mh]
w_max_indexs = [i for i, v in enumerate(w_list) if v == mw]

double_chance = False
# print("---")
for h_index in h_max_indexs:
  if double_chance:
    break
  for w_index in w_max_indexs:
    if double_chance:
      break
    # chance = h_w_list[h_index][w_index] != 1
    chance = h_w_list.count([h_index + 1, w_index + 1]) == 0
    # print(h_w_list)
    # print([h_index, w_index], chance)


    # print(h_index, w_index, chance)
    if chance:
      double_chance = True


if double_chance:
  result = mh + mw
else:
  result = mh + mw -1

print(result)


# Optimized solution
# -*- coding: utf-8 -*-

# スペース区切りの整数の入力
h, w, m = list(map(int, input().split()))

h_list = [0]*h
w_list = [0]*w

# h_w_list = [[0 for j in range(w)] for i in range(h)]
# h_w_list = []
h_w_list = set()

for zzz in range(m):
  # print("---")
  bom_h, bom_w = list(map(int, input().split()))
  # print(bom_h, bom_w)
  h_list[bom_h-1] += 1
  w_list[bom_w-1] += 1

  # h_w_list[bom_h-1][bom_w-1] = 1
  # h_w_list.append([bom_h, bom_w])
  h_w_list.add((bom_h, bom_w))

mh = max(h_list)
mw = max(w_list)
h_max_indexs = [i for i, v in enumerate(h_list) if v == mh]
w_max_indexs = [i for i, v in enumerate(w_list) if v == mw]

double_chance = False
# print("---")
for h_index in h_max_indexs:
  if double_chance:
    break
  for w_index in w_max_indexs:
    if double_chance:
      break
    # chance = h_w_list.count([h_index + 1, w_index + 1]) == 0
    chance = (h_index + 1, w_index + 1) not in h_w_list

    if chance:
      double_chance = True


if double_chance:
  result = mh + mw
else:
  result = mh + mw -1

print(result)
# Original solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


def LI(): return list(map(int, sys.stdin.readline().split()))


def I(): return int(sys.stdin.readline())


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

A=[[v,i] for i,v in list(D1.items())]+[[-INF,-INF]]
B=[[v,i] for i,v in list(D2.items())]+[[-INF,-INF]]
A.sort(reverse=True)
B.sort(reverse=True)
a_now=0
b_now=0
ans=-INF
while True:
    av,ak=A[a_now]
    bv,bk = B[b_now]
    ans=max(ans,av+bv-int((ak,bk) in s))
    if a_now==len(A)-2 and b_now==len(B)-2:
        break
    elif A[a_now+1][0]+B[b_now][0]>A[a_now][0]+B[b_now+1][0]:
        a_now+=1
    else:
        b_now+=1

print(ans)






# Optimized solution
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = float('inf')


def LI(): return list(map(int, sys.stdin.readline().split()))


def I(): return int(sys.stdin.readline())


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

h_max = max(D1.values())
w_max = max(D2.values())
A=[i for i,v in list(D1.items()) if v==h_max]
B=[i for i,v in list(D2.items()) if v==w_max]

flg = 1
for i in A:
    for j in B:
        if (i, j) not in s:
            flg = 0
            break

print((w_max+h_max-flg))
# Original solution
import sys
input = sys.stdin.readline

r,c,m=list(map(int,input().split()))
q=[list([int(x)-1 for x in input().split()]) for _ in range(m)]
M=[[0 for i in range(c)] for _ in range(r)]
for i,j in q:
    M[i][j]=1

rows = [0]*r
cols = [0]*c

for i in range(r):
    rows[i]=sum(M[i])

for i in range(c):
    A = [M[j][i] for j in range(r)]
    cols[i] = sum(A)


#print(rows,cols)
MAX = 0
for i in range(r):
    for j in range(c):
        if M[i][j]==1:
            MAX = max(MAX,rows[i]+cols[j]-1)
        else:
            MAX = max(MAX,rows[i]+cols[j])
print(MAX)
    



    


# Optimized solution
import sys
input = sys.stdin.readline

r,c,m=list(map(int,input().split()))
q=set(tuple([int(x)-1 for x in input().split()]) for _ in range(m))
rows = [0]*r
cols = [0]*c

for i,j in q:
    rows[i]+=1
    cols[j]+=1

MAXR = max(rows)
MAXC = max(cols)

ans = MAXR+MAXC-1

rlist=[]
clist=[]

for i in range(r):
    if rows[i]==MAXR:
        rlist.append(i)

for j in range(c):
    if cols[j]==MAXC:
        clist.append(j)
   
for i in rlist:
    for j in clist:
        if (i,j) in q:
            continue
        else:
            ans+=1
            print(ans)
            sys.exit()
print(ans)
# Original solution
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_is = set()
    for _ in range(target_count):
        bom_h, bom_w = [int(x) - 1 for x in input().split()]
        count_by_height[bom_h] += 1
        count_by_width[bom_w] += 1
        bomb_is.add((bom_h, bom_w))
    max_h = max(v for v in list(count_by_height.values()))
    max_w = max(v for v in list(count_by_width.values()))
    max_h_index = [i for i, x in list(count_by_height.items()) if x == max_h]
    max_w_index = [i for i, x in list(count_by_width.items()) if x == max_w]
    no_cross = any(
        (hh, ww) not in bomb_is for hh in max_h_index for ww in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    ans = main()
    print(ans)


# Optimized solution
from collections import defaultdict


def main():
    height, width, target_count = [int(x) for x in input().split()]
    count_by_height = defaultdict(int)
    count_by_width = defaultdict(int)
    bomb_locations = set()
    for _ in range(target_count):
        h, w = [int(x) - 1 for x in input().split()]
        count_by_height[h] += 1
        count_by_width[w] += 1
        bomb_locations.add((h, w))
    max_h = max(v for v in list(count_by_height.values()))
    max_w = max(v for v in list(count_by_width.values()))
    max_h_index = [i for i, x in list(count_by_height.items()) if x == max_h]
    max_w_index = [i for i, x in list(count_by_width.items()) if x == max_w]
    no_cross = any((h, w) not in bomb_locations
                   for h in max_h_index for w in max_w_index)
    return max_h + max_w - (not no_cross)


if __name__ == '__main__':
    print((main()))
# Original solution
# -*- coding: utf-8 -*-
import sys 
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = list(map(int,readline().split()))
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
data = [[False]*(W+1) for i in range(H+1)]
 
for i in range(M):
    h,w = list(map(int,readline().split()))
    data[h][w] = True
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
maxh = max(h_cnt)
maxw = max(w_cnt)
maxhInd = []
maxwInd = []
maxhInd = [i for i,a in enumerate(h_cnt) if a == maxh]
maxwInd = [i for i,a in enumerate(w_cnt) if a == maxw]
maxhCnt = len(maxhInd)
maxwCnt = len(maxwInd)

ans = maxh+maxw

if maxhCnt * maxwCnt > M:
    print(ans)
else:
    t = list(itertools.product(maxhInd, maxwInd))
    for h,w in t:
        if data[h][w] == False:
            print(ans)
            sys.exit()
    print((ans-1))

# Optimized solution
# -*- coding: utf-8 -*-
import sys 
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W, M = list(map(int,readline().split()))
h_cnt = [0]*(H+1)
w_cnt = [0]*(W+1)
bomb = []
 
for i in range(M):
    h,w = list(map(int,readline().split()))
    bomb.append((h,w))
    h_cnt[h] += 1 
    w_cnt[w] += 1
    
maxh = max(h_cnt)
maxw = max(w_cnt)
maxhCnt = h_cnt.count(maxh)
maxwCnt = w_cnt.count(maxw)

total = maxhCnt*maxwCnt
ans = maxh+maxw
cnt = 0
for h,w in bomb:
    if h_cnt[h] == maxh and w_cnt[w] == maxw:
       cnt += 1

print((ans-1 if cnt == total else ans))
# Original solution
h,w,m=list(map(int,input().split()))
lh=[0]*h
lw=[0]*w
l=[[0 for _ in range(w)] for _ in range(h)]
for i in range(m):
  h1,w1=list(map(int,input().split()))
  l[h1-1][w1-1]=1
  lh[h1-1]+=1
  lw[w1-1]+=1
hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    lw2.append(i)
 
s=1
for m in lh2:
  for m2 in lw2:
    if l[m][m2]==0:
      s=0
      
print((hmax+wmax-s))

# Optimized solution
h,w,m=list(map(int,input().split()))
lh=[0]*h
lw=[0]*w
l=set()
for i in range(m):
  h1,w1=input().split()
  l.add(h1+"_"+w1)
  lh[int(h1)-1]+=1
  lw[int(w1)-1]+=1

hmax=max(lh)
wmax=max(lw)
lh2=[]
lw2=[]
for i in range(h):
  if lh[i]==hmax:
    lh2.append(i)
for i in range(w):
  if lw[i]==wmax:
    for m in lh2:
      if str(m+1)+"_"+str(i+1) not in l:
        print((hmax+wmax))
        exit()      
print((hmax+wmax-1))
# Original solution
h, w, m = list(map(int, input().split()))
HW = [[*[int(x)-1 for x in input().split()]] for _ in range(m)]

sum_h = [[0,0] for _ in range(h)] # [sum, index]
sum_w = [[0,0] for _ in range(w)]
for i in range(m):
    h,w = HW[i]
    sum_h[h][0] += 1
    sum_w[w][0] += 1
    sum_h[h][1] = h
    sum_w[w][1] = w

h_num_ix = {}
for num,ix in sum_h:
    if not num in h_num_ix:
        h_num_ix[num] = set()
    h_num_ix[num].add(ix)

w_num_ix = {}
for num,ix in sum_w:
    if not num in w_num_ix:
        w_num_ix[num] = set()
    w_num_ix[num].add(ix)

max_h_num = max(h_num_ix)
max_w_num = max(w_num_ix)

# print(h_num_ix)
# print(w_num_ix)
# print(max_h_num)
# print(max_w_num)
# print('====')

max_num = max_h_num + max_w_num - 1
for h_ix in h_num_ix[max_h_num]:
    for w_ix in w_num_ix[max_w_num]:
        num = max_h_num + max_w_num
        if [h_ix, w_ix] in HW: continue
        max_num += 1
        print(max_num)
        exit()
print(max_num)


# Optimized solution
h, w, m = list(map(int, input().split()))
HW = [[*[int(x)-1 for x in input().split()]] for _ in range(m)]

sum_h = [[0,0] for _ in range(h)] # [sum, index]
sum_w = [[0,0] for _ in range(w)]
for i in range(m):
    h,w = HW[i]
    sum_h[h][0] += 1
    sum_w[w][0] += 1
    sum_h[h][1] = h
    sum_w[w][1] = w

h_num_ix = {}
for num,ix in sum_h:
    if not num in h_num_ix:
        h_num_ix[num] = set()
    h_num_ix[num].add(ix)

w_num_ix = {}
for num,ix in sum_w:
    if not num in w_num_ix:
        w_num_ix[num] = set()
    w_num_ix[num].add(ix)

max_h_num = max(h_num_ix)
max_w_num = max(w_num_ix)

# print(sorted(HW))
# print('---')
# print(h_num_ix)
# print(w_num_ix)
# print(max_h_num)
# print(max_w_num)
# print('====')

SHW = set()
for h,w in HW:
    SHW.add((h,w))
# print(SHW)

max_num = max_h_num + max_w_num - 1
for h_ix in h_num_ix[max_h_num]:
    for w_ix in w_num_ix[max_w_num]:
        num = max_h_num + max_w_num
        # if [h_ix, w_ix] in HW: continue
        if (h_ix, w_ix) in SHW: continue
        max_num += 1
        print(max_num)
        exit()
print(max_num)
# Original solution
H, W, M = list(map(int, input().split()))
HW = set(tuple([int(x)-1 for x in input().split()]) for _ in range(M))

sum_h = [0]*H; sum_w = [0]*W
for h, w in HW:
    sum_h[h] += 1
    sum_w[w] += 1

max_h_num = 0
h_num_ix = {}
for i in range(H):
    num = sum_h[i]
    if num == 0: continue
    if not num in h_num_ix: h_num_ix[num] = set()
    h_num_ix[num].add(i)
    max_h_num = max(max_h_num, num)

max_w_num = 0
w_num_ix = {}
for i in range(W):
    num = sum_w[i]
    if num == 0: continue
    if not num in w_num_ix: w_num_ix[num] = set()
    w_num_ix[num].add(i)
    max_w_num = max(max_w_num, num)

max_num = max_h_num + max_w_num - 1
for h_ix in h_num_ix[max_h_num]:
    for w_ix in w_num_ix[max_w_num]:
        if (h_ix, w_ix) in HW: continue
        print((max_num + 1))
        exit()
print(max_num)


# Optimized solution
H, W, M = list(map(int, input().split()))

HW = set()
sum_h = [0]*H; sum_w = [0]*W
max_sum_h = max_sum_w = 0
for _ in range(M):
    h, w = [int(x)-1 for x in input().split()]
    HW.add((h, w))
    sum_h[h] += 1
    sum_w[w] += 1
    max_sum_h = max(max_sum_h, sum_h[h])
    max_sum_w = max(max_sum_w, sum_w[w])

hs = []; ws = []
for i in range(H):
    if sum_h[i] == max_sum_h: hs.append(i)
for i in range(W):
    if sum_w[i] == max_sum_w: ws.append(i)

ans = max_sum_h + max_sum_w - 1
for h in hs:
    for w in ws:
        if (h, w) in HW: continue
        print((ans + 1))
        exit()
print(ans)
# Original solution
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: list(map(int, stdin.readline().split()))
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
ans=0
mass=[]
for i in range(M):
    h,w=nm()
    mass.append((h,w))
    r[h]+=1
    c[w]+=1

inds1=list(range(10**6))
inds1.sort(reverse=True,key=lambda x: r[x])

inds2=list(range(10**6))
inds2.sort(reverse=True,key=lambda x: c[x])

r.sort(reverse=True)
c.sort(reverse=True)

r1=0
l1=0

while(1):
    if(r[r1+1]==r[r1]):
        r1+=1
    else:
        break

while(1):
    if(c[l1+1]==c[l1]):
        l1+=1
    else:
        break



flag=False
for i in range(r1+1):
    for j in range(l1+1):
        flag=True
        for k in mass:
                if(k[0]==inds1[i] and k[1]==inds2[j]):
                    flag=False
        if(flag==True):
            print((r[0]+c[0]))
            sys.exit(0)


print((r[0]+c[0]-1))






# Optimized solution
import sys
import  math
import fractions
from collections import defaultdict
import heapq
from bisect import bisect_left,bisect

stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: list(map(int, stdin.readline().split()))
nl = lambda: list(map(int, stdin.readline().split()))

H,W,M=nm()
r=[0]*(10**6)
c=[0]*(10**6)
mass=set()
for i in range(M):
    h,w=nm()
    mass.add(H*h+w)
    r[h]+=1
    c[w]+=1

rl=[]
cl=[]

r_max=0
for i in range(1,H+1):
    r_max=max(r[i],r_max)
    
c_max=0
for i in range(1,W+1):
    c_max=max(c[i],c_max)

for i in range(1,H+1):
    if(r[i]==r_max):
        rl.append(i)

for i in range(1,W+1):
    if(c[i]==c_max):
        cl.append(i)



for i in rl:
    for j in cl:
        if(i*H+j not in mass):
            print((r_max+c_max))
            sys.exit(0)


print((r_max+c_max-1))
# Original solution
h,w,m = list(map(int,input().split()))
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = list(map(int,input().split()))
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
for i in range(1,h+1):
  if row[i]!=r:
    continue
  for j in range(1,w+1):
    if col[j]!=c:
      continue
    if (i,j) not in bombs:
      print((r+c))
      exit()
else:
  print((r+c-1))

# Optimized solution
h,w,m = list(map(int,input().split()))
row = [0]*(h+1)
col = [0]*(w+1)
bombs = set([])
for i in range(m):
  a,b = list(map(int,input().split()))
  row[a] += 1
  col[b] += 1
  bombs.add((a,b))
r,c = max(row),max(col)
rcnt,ccnt = 0,0
for v in row:
  if v==r:
    rcnt += 1
for v in col:
  if v==c:
    ccnt += 1
doubled = 0
for i,j in bombs:
  if row[i]==r and col[j]==c:
    doubled += 1
if doubled==rcnt*ccnt:
  print((r+c-1))
else:
  print((r+c))