from bisect import bisect_left n, m, q = map(int, input().split()) xy = [list(map(int, input().split())) for _ in range(q)] xy.sort(key = lambda x:(x[0], -x[1])) lst = [] for _, y in xy: p = bisect_left(lst, y) if p == len(lst): lst.append(p) else: lst[p] = y print(len(lst))