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 by -b ascending (b descending) pairs.sort() # Extract the y values in the sorted order, converting back to original values ys = [-b for a, b in pairs] # Compute the length of the longest strictly increasing subsequence 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))