mod = 1000000007 eps = 10**-9 def main(): import sys from bisect import bisect_left input = sys.stdin.readline N, M, Q = map(int, input().split()) XY = [] for _ in range(Q): XY.append(tuple(map(int, input().split()))) XY.sort(key=lambda x: x[1], reverse=True) XY.sort(key=lambda x: x[0]) LIS = [0] for _, y in XY: j = bisect_left(LIS, y) if j == len(LIS): LIS.append(y) else: LIS[j] = y print(len(LIS) - 1) if __name__ == '__main__': main()