from bisect import bisect_left N, M, Q = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(Q)] A.sort(key=lambda x: (x[0], -x[1])) 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)