def lcs(S,T,A): dp=[[0]*(len(T)+1)for _ in[0]*(len(S)+1)] for i in range(1,len(S)+1): for j in range(1,len(T)+1): if A[S[i-1]][T[j-1]]==1: dp[i][j]=dp[i-1][j-1]+1 else: dp[i][j]=max(dp[i-1][j],dp[i][j-1]) length=dp[len(S)][len(T)] return length def main(): N,M,Q=map(int,input().split()) A=[[0]*N for i in range(N)] for i in range(Q): a,b=map(int,input().split()) A[a-1][b-1]=1 A[b-1][a-1]=1 S=list(range(N)) T=list(range(M)) ans=lcs(S,T,A) print(ans) return main()