import bisect n, m, q = map(int, input().split()) pairs = [tuple(map(int, input().split())) for _ in range(q)] pairs.sort() groups = [] current_a = None current_ys = [] for a, b in pairs: if a != current_a: if current_a is not None: groups.append(current_ys) current_a = a current_ys = [] current_ys.append(b) if current_ys: groups.append(current_ys) dp = [] for ys in groups: if not dp: if ys: dp.append(ys[0]) else: last_y = dp[-1] idx = bisect.bisect_right(ys, last_y) if idx < len(ys): dp.append(ys[idx]) print(len(dp))