from sys import stdin import bisect n, m, q, *indata = map(int, stdin.read().split()) offset = 0 hq = [] for i in range(q): s, t = indata[offset + 2*i],indata[offset + 2*i+1] hq.append((s,-t)) hq.sort() dp = [-hq[0][1]] ans = 1 for i in range(1,q): a = -hq[i][1] kari = bisect.bisect_left(dp,a) if kari == ans: dp.append(a) ans += 1 else: dp[kari] = a print("{}".format(ans))