from bisect import bisect_left n, m, q = map(int, input().split()) lst = [[] for _ in range(n)] for _ in range(q): x, y = map(int, input().split()) lst[x - 1].append(y) Y = [] for ls in lst: ls.sort(reverse = True) Y += ls lst = [] for y in Y: p = bisect_left(lst, y) if p == len(lst): lst.append(y) else: lst[p] = y print(len(lst))