import bisect n, m, q = map(int, input().split()) pairs = [] for _ in range(q): a, b = map(int, input().split()) pairs.append((a, b)) # Sort by a ascending, then b descending to handle same a's correctly pairs.sort(key=lambda x: (x[0], -x[1])) # Extract the list of y's (b values) in the sorted order ys = [b for a, b in pairs] # Compute the longest strictly increasing subsequence using binary search tails = [] for y in ys: idx = bisect.bisect_left(tails, y) if idx == len(tails): tails.append(y) else: tails[idx] = y print(len(tails))