n,K=map(int,input().split()) a=[int(input(),5) for i in range(n)] q=[0]*(5**K) for v in a: q[v]=1 for j in range(K): for i in reversed(range(5**K)): if (i//(5**j))%5>0: q[i-(5**j)]+=q[i] print(n-sum(q[v]==1 for v in a))