n, m, q = map(int, input().split()) pairs = [] for _ in range(q): a, b = map(int, input().split()) pairs.append((a, b)) pairs.sort(key=lambda x: (x[0], x[1])) class BIT: def __init__(self, size): self.size = size self.tree = [0] * (self.size + 1) # 1-based indexing def update(self, idx, value): while idx <= self.size: if self.tree[idx] < value: self.tree[idx] = value else: break idx += idx & -idx def query(self, idx): res = 0 while idx > 0: if self.tree[idx] > res: res = self.tree[idx] idx -= idx & -idx return res bit = BIT(m) max_dp = 0 current_a = None group = [] for a, b in pairs: if a != current_a: if group: temp_dp = [] for (a_p, b_p) in group: max_val = bit.query(b_p - 1) current_dp = max_val + 1 temp_dp.append((b_p, current_dp)) if current_dp > max_dp: max_dp = current_dp for (b_p, current_dp) in temp_dp: if current_dp > bit.query(b_p): bit.update(b_p, current_dp) current_a = a group = [(a, b)] else: group.append((a, b)) if group: temp_dp = [] for (a_p, b_p) in group: max_val = bit.query(b_p - 1) current_dp = max_val + 1 temp_dp.append((b_p, current_dp)) if current_dp > max_dp: max_dp = current_dp for (b_p, current_dp) in temp_dp: if current_dp > bit.query(b_p): bit.update(b_p, current_dp) print(max_dp)