def solve(): N,K=map(int,input().split()) S=[None]*N for i in range(N): S[i]=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): A=S[i]; B=0 for d in range(K): r=A%5 B=5*B+(r-1 if r!=0 else 0) if A!=B and X[B]!=0: ans+=1 return ans #================================================== print(solve())