def solve(): N,K=map(int,input().split()) S=[None]*N for i in range(N): S[i]=int("4"*K,5)-int(input(),5) X=[0]*pow(5,K) for i in range(N): X[S[i]]+=1 for d in range(K): t=pow(5,d) for i in range(pow(5,K)): if i//(5*t)==(i+t)//(5*t): X[i+t]+=X[i] ans=0 for i in range(N): if X[S[i]]>=2: ans+=1 return ans #================================================== print(solve())