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 descending pairs.sort(key=lambda x: (x[0], -x[1])) # Extract the list of b's (female indices) b_list = [b for a, b in pairs] # Compute the length of the longest increasing subsequence tails = [] for num in b_list: idx = bisect.bisect_left(tails, num) if idx == len(tails): tails.append(num) else: tails[idx] = num print(len(tails))