from bisect import bisect_left n, m, q = map(int, input().split()) Q = [list(map(int, input().split())) for _ in range(q)] Q.sort(key=lambda x: (x[0], x[1])) LIS = [] for i in range(q): b = Q[i][1] idx = bisect_left(LIS, b) if idx == len(LIS): LIS.append(b) else: LIS[idx] = b print(len(LIS))