import sys input = sys.stdin.readline N,K=map(int,input().split()) S=[list(map(int,list(input().strip()))) for i in range(N)] X=[] for s in S: a=0 for i in range(len(s)): a+=(5**i)*s[i] X.append(a) USED=[0]*(5**8+1) SET=set(X) ANS=0 for i in range(5**8,-1,-1): if i in SET: if USED[i]==1: ANS+=1 USED[i]=1 if USED[i]==1: for j in range(8): if (i%(5**(j+1)))//(5**j)!=0: USED[i-(5**j)]=1 print(ANS)