import sys
import itertools


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main() import sys sys import itertools itertools def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans resolve H, W, M = map(int, next(in_).split()) H map(int, next(in_).split()) map int next(in_).split() (in_).split (in_) next in_ split W M targets = tuple(tuple(map(int, line.split())) for line in in_) targets tuple(tuple(map(int, line.split())) for line in in_) tuple tuple(map(int, line.split())) tuple map(int, line.split()) map int line.split() line.split line split target_h = {} target_h {} target_w = {} target_w {} target_hw = set() target_hw set() set for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

     h w targets target_h[h] = target_h.setdefault(h, 0) + 1 target_h[h] target_h h target_h.setdefault(h, 0) + 1 target_h.setdefault(h, 0) target_h.setdefault target_h setdefault h 0 1 target_w[w] = target_w.setdefault(w, 0) + 1 target_w[w] target_w w target_w.setdefault(w, 0) + 1 target_w.setdefault(w, 0) target_w.setdefault target_w setdefault w 0 1 target_hw.add((h, w)) target_hw.add target_hw add (h, w) h w max_h = max(target_h.values()) max_h max(target_h.values()) max target_h.values() target_h.values target_h values max_w = max(target_w.values()) max_w max(target_w.values()) max target_w.values() target_w.values target_w values h for h, v in target_h.items() if max_h == v for h, v in target_h.items() if max_h == v h v target_h.items() target_h.items target_h items max_h == v max_h v if max_h == v h h_set = {h for h, v in target_h.items() if max_h == v} h_set w for w, v in target_w.items() if max_w == v for w, v in target_w.items() if max_w == v w v target_w.items() target_w.items target_w items max_w == v max_w v if max_w == v w w_set = {w for w, v in target_w.items() if max_w == v} w_set ans = max_h + max_w - 1 ans max_h + max_w - 1 max_h + max_w max_h max_w 1 for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
     hw itertools.product(h_set, w_set) itertools.product itertools product h_set w_set if hw not in target_hw:
            ans += 1
            break
    
     hw not in target_hw hw target_hw ans += 1 ans 1 break return ans ans in_ in_ def main():
    answer = resolve(sys.stdin.buffer)
    print(answer) main answer = resolve(sys.stdin.buffer) answer resolve(sys.stdin.buffer) resolve sys.stdin.buffer sys.stdin sys stdin buffer print(answer) print answer if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans resolve def main():
    answer = resolve(sys.stdin.buffer)
    print(answer) def main():
    answer = resolve(sys.stdin.buffer)
    print(answer) main
import sys
import itertools


def resolve(in_):
    H, W, M = map(int, next(in_).split())
    targets = tuple(tuple(map(int, line.split())) for line in in_)
    
    target_h = {}
    target_w = {}
    target_hw = set()
    for h, w in targets:
        target_h[h] = target_h.setdefault(h, 0) + 1
        target_w[w] = target_w.setdefault(w, 0) + 1
        target_hw.add((h, w))

    max_h = max(target_h.values())
    max_w = max(target_w.values())

    h_set = {h for h, v in target_h.items() if max_h == v}
    w_set = {w for w, v in target_w.items() if max_w == v}

    ans = max_h + max_w - 1
    for hw in itertools.product(h_set, w_set):
        if hw not in target_hw:
            ans += 1
            break
    
    return ans


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()
