N,M=map(int,input().split()) box=[set() for _ in range(N)] #色ごとに箱を格納 for _ in range(M): b,c=map(int,input().split()) box[c-1].add(b) ans=0 for i in range(N): ans+=max(0,len(box[i])-1) print(ans)