n,m,Q=map(int,input().split()) p=[tuple(map(int,input().split())) for i in range(Q)] p.sort() X=Q+1 q=[X]*(Q+2) from bisect import bisect_left for _,y in p: q[bisect_left(q,y)]=y for i in range(Q+2): if q[i]==X: print(i) exit()