n, m, q = map(int, input().split()) ab = [list(map(int, input().split())) for i in range(q)] ab.sort(key=lambda x: (x[0], -x[1])) INF = 10 ** 9 from bisect import bisect_left dp = [INF] * (q + 1) for a, b in ab: dp[bisect_left(dp, b)] = b print(bisect_left(dp, INF))