import sys input = sys.stdin.readline def to_num(s): ret = 0 for c in s: k = ord(c) - ord('0') ret <<= 3 ret += k return ret N, K = map(int, input().split()) st = set([to_num(input()[:-1]) for _ in [0] * N]) visited = set() for sv in st: if(sv in visited): continue stk = [sv] while(stk): v = stk.pop() for i in range(K): k = i * 3 if(((v >> k) & 7) == 0): continue nv = v - (1 << k) if(nv in visited): continue visited.add(nv) stk.append(nv) ans = len(visited & st) print(ans)