import sys,random from collections import deque from heapq import heappush,heappop input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) N,M,Q = mi() pair = [[] for i in range(N+1)] for _ in range(Q): a,b = mi() pair[a].append(b) INF = 10**9 dp = [0 for w in range(M+1)] for i in range(N): ndp = [x for x in dp] for w in pair[i+1]: ndp[w] = max(ndp[w],dp[w-1]+1) dp = ndp for w in range(1,M+1): dp[w] = max(dp[w],dp[w-1]) print(max(dp))