class FenwickTreeMax: def __init__(self, size): self.n = size self.data = [0] * (self.n + 2) # 1-based indexing self.tree = [0] * (self.n + 2) def update(self, idx, value): if idx > self.n: return if self.data[idx] >= value: return self.data[idx] = value while idx <= self.n: if self.tree[idx] < value: self.tree[idx] = value else: break idx += idx & -idx def query(self, idx): res = 0 while idx > 0: res = max(res, self.tree[idx]) idx -= idx & -idx return res def get(self, idx): return self.data[idx] n, m, q = map(int, input().split()) pairs = [] for _ in range(q): a, b = map(int, input().split()) pairs.append((a, b)) # Sort pairs by a (ascending), then by b (ascending) pairs.sort(key=lambda x: (x[0], x[1])) ft = FenwickTreeMax(m) max_ans = 0 for a, b in pairs: if b == 1: prev_max = 0 else: prev_max = ft.query(b - 1) current = prev_max + 1 if current > ft.get(b): ft.update(b, current) if current > max_ans: max_ans = current print(max_ans)