I,R=input,range N,K=map(int,I().split()) p=[pow(5,i)for i in R(K+1)] b=[0]*p[K] S=[0]*N for i in R(N): S[i]=int(I(),5) b[S[i]]=1 a=0 for i in R(N): L=[S[i]] if b[S[i]]<2 else [] while len(L): s=L.pop() for j in R(K): t=s-p[j] if s%p[j+1]//p[j]*(b[t]<2): L.append(t) a,b[t]=a+(b[t]==1),2 print(a)