import sys input = sys.stdin.readline n,m,q = map(int,input().split()) ab = [list(map(int,input().split())) for _ in range(q)] ab.sort() li = [] for a,b in ab: li.append(b) def LIS(L): from bisect import bisect_left seq = [] for ai in L: pos = bisect_left(seq, ai) if len(seq) <= pos: seq.append(ai) else: seq[pos] = ai return len(seq) print(LIS(li))