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