Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = []
max_cnt = 0
for h,cnt in HL:
    if max_cnt<=cnt:
        HS.append([h,cnt])
        max_cnt = max(max_cnt,cnt)
        continue
    break

WS = []
max_cnt = 0
for w,cnt in WL:
    if max_cnt<=cnt:
        WS.append([w,cnt])
        max_cnt = max(max_cnt,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
#cross_cnt = 0
#for hw in HW.keys():
#    h,w = hw
#    if h in HS and w in WS:
#        cross_cnt+=1


for h,hcnt in HS:
    for w,wcnt in WS:
        if (h,w) in HW:
            cnt = hcnt+wcnt-1
            ans = max(ans,cnt)
            continue
        cnt = hcnt+wcnt
        ans = max(ans,cnt)

print(ans)

















Fixed submission:
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = {}
max_cnth = 0
for h,cnt in HL:
    if max_cnth<=cnt:
        HS[h] = cnt
        max_cnth = max(max_cnth,cnt)
        continue
    break

WS = {}
max_cntw = 0
for w,cnt in WL:
    if max_cntw<=cnt:
        WS[w] = cnt
        max_cntw = max(max_cntw,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
cross_cnt = 0
for hw in HW.keys():
    h,w = hw
    if h in HS and w in WS:
        cross_cnt+=1
if len(WS) * len(HS)==cross_cnt:
    print(max_cnth+max_cntw-1)
    exit()
print(max_cnth+max_cntw)


#for h,hcnt in HS:
#    for w,wcnt in WS:
#        if (h,w) in HW:
#            cnt = hcnt+wcnt-1
#            ans = max(ans,cnt)
#            continue
#        cnt = hcnt+wcnt
#        ans = max(ans,cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = []
max_cnt = 0
for h,cnt in HL:
    if max_cnt<=cnt:
        HS.append([h,cnt])
        continue
    break

WS = []
max_cnt = 0
for w,cnt in WL:
    if max_cnt<=cnt:
        WS.append([w,cnt])
        continue
    break

cnt = 0
ans = 0
for h,hcnt in HS:
    for w,wcnt in WS:
        if (h,w) in HW:
            cnt = hcnt+wcnt-1
            ans = max(ans,cnt)
            continue
        cnt = hcnt+wcnt
        ans = max(ans,cnt)

print(ans)

















Fixed submission:
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = {}
max_cnth = 0
for h,cnt in HL:
    if max_cnth<=cnt:
        HS[h] = cnt
        max_cnth = max(max_cnth,cnt)
        continue
    break

WS = {}
max_cntw = 0
for w,cnt in WL:
    if max_cntw<=cnt:
        WS[w] = cnt
        max_cntw = max(max_cntw,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
cross_cnt = 0
for hw in HW.keys():
    h,w = hw
    if h in HS and w in WS:
        cross_cnt+=1
if len(WS) * len(HS)==cross_cnt:
    print(max_cnth+max_cntw-1)
    exit()
print(max_cnth+max_cntw)


#for h,hcnt in HS:
#    for w,wcnt in WS:
#        if (h,w) in HW:
#            cnt = hcnt+wcnt-1
#            ans = max(ans,cnt)
#            continue
#        cnt = hcnt+wcnt
#        ans = max(ans,cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = []
max_cnt = 0
for h,cnt in HL:
    if max_cnt<=cnt:
        HS.append([h,cnt])
        continue
    break

WS = []
max_cnt = 0
for w,cnt in WL:
    if max_cnt<=cnt:
        WS.append([w,cnt])
        continue
    break

cnt = 0
ans = 0
for h,hcnt in HS:
    for w,wcnt in WS:
        if (h,w) in HW:
            cnt = hcnt+wcnt-1
            ans = max(ans,cnt)
            continue
        cnt = hcnt+wcnt
        ans = max(ans,cnt)

print(ans)

















Fixed submission:
H,W,M = map(int,input().split())
T = [0] * M
H_cnt = {}
W_cnt = {}
HW = {}
for i in range(M):
    h,w = map(int,input().split())
    if not h in H_cnt:
        H_cnt[h] = 0
    if not w in W_cnt:
        W_cnt[w] = 0
    H_cnt[h] += 1
    W_cnt[w] += 1
    HW[(h,w)] = 1

HL = [[h,cnt] for h,cnt in H_cnt.items()]
WL = [[w,cnt] for w,cnt in W_cnt.items()]

HL.sort(key=lambda x: x[1],reverse=True)
WL.sort(key=lambda x: x[1],reverse=True)

HS = {}
max_cnth = 0
for h,cnt in HL:
    if max_cnth<=cnt:
        HS[h] = cnt
        max_cnth = max(max_cnth,cnt)
        continue
    break

WS = {}
max_cntw = 0
for w,cnt in WL:
    if max_cntw<=cnt:
        WS[w] = cnt
        max_cntw = max(max_cntw,cnt)
        continue
    break

cnt = 0
ans = 0

# ここの判定を高速にする
cross_cnt = 0
for hw in HW.keys():
    h,w = hw
    if h in HS and w in WS:
        cross_cnt+=1
if len(WS) * len(HS)==cross_cnt:
    print(max_cnth+max_cntw-1)
    exit()
print(max_cnth+max_cntw)


#for h,hcnt in HS:
#    for w,wcnt in WS:
#        if (h,w) in HW:
#            cnt = hcnt+wcnt-1
#            ans = max(ans,cnt)
#            continue
#        cnt = hcnt+wcnt
#        ans = max(ans,cnt)