N, M, Q = map(int, input().split()) X = [[] for _ in range(N)] for _ in range(Q): a, b = map(int, input().split()) X[a-1].append(b - 1) Y = [0] * (M + 1) for i, x in enumerate(X): nY = Y[:] for b in x: nY[b+1] = max(nY[b+1], max(Y[:b+1]) + 1) Y = nY print(max(Y))