from bisect import bisect_left N,M,Q = map(int,input().split()) AB = [list(map(int,input().split())) for _ in range(Q)] E = [[] for _ in range(M)] for a, b in AB: a -= 1 b -= 1 E[b].append(a) X = [] for i in range(M): if not E[i]: continue E[i].sort(reverse = True) for s in E[i]: if not X: X.append(s) else: a = bisect_left(X,s) if a == len(X): X.append(s) else: X[a] = s print(len(X))