n,m=map(int,input().split()) a=0 C=[0]*(n+1) for i in range(n): b,c=map(int,input().split()) if C[c]>0 and C[c]!=b:a+=1 else:C[c]=b print(a)