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