from bisect import bisect_left N, M, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] B = [0]*Q for i in range(Q): a, b = A[i] c = 2**10-1-b B[i] = a*(2**10)+c B.sort() INF = 10**9 dp = [INF]*(N+M+1) dp[0] = 0 for v in B: b = 2**10-1-(v % (2**10)) ind = bisect_left(dp, b) dp[ind] = min(dp[ind], b) ans = 0 while dp[ans+1] < INF: ans += 1 print(ans)