""" """ from sys import stdin import sys N,M,Q = map(int,stdin.readline().split()) dp = [[0] * (M+1) for i in range(N+1)] ab = set() for i in range(Q): a,b = map(int,stdin.readline().split()) ab.add((a,b)) for i in range(N+1): for j in range(M+1): dp[i][j] = max(dp[i-1][j] , dp[i][j-1]) if (i,j) in ab: dp[i][j] = max(dp[i][j] , dp[i-1][j-1] + 1) print (dp[-1][-1])