class FenwickTreeMax: 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 # No need to proceed further idx += idx & -idx def query(self, idx): res = 0 while idx > 0: res = max(res, self.tree[idx]) idx -= idx & -idx return res def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 M = int(input[ptr]) ptr += 1 Q = int(input[ptr]) ptr += 1 pairs = [] for _ in range(Q): a = int(input[ptr]) ptr += 1 b = int(input[ptr]) ptr += 1 pairs.append((a, b)) # Sort pairs by a ascending, then b descending pairs.sort(key=lambda x: (x[0], -x[1])) ft = FenwickTreeMax(M) ans = 0 for a, b in pairs: # Query the maximum value in [1, b-1] current_max = ft.query(b - 1) current_length = current_max + 1 if current_length > ans: ans = current_length ft.update(b, current_length) print(ans) if __name__ == '__main__': main()