n, m, q = map(int, input().split()) C = [[0 for _ in range(m)] for _ in range(n)] for _ in range(q): a, b = map(int, input().split()) C[a - 1][b - 1] = 1 DP = [[0 for _ in range(m + 1)] for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, m + 1): if C[i - 1][j - 1] == 1: DP[i][j] = DP[i - 1][j - 1] + 1 else: DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]) print(DP[n][m])