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