from heapq import * N,M,Q = map(int,input().split()) l = [[] for _ in range(N)] for _ in range(Q): a,b = map(int,input().split()) a -= 1 b -= 1 l[a].append(b) check = [False]*M ans,before = 0,-1 for i in range(N): while l[i]: m = heappop(l[i]) if check[m] or before >= m: continue before = m check[m] = True ans += 1 break print(ans)