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