import sys from collections import deque 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]) init = (1 << (K << 1)) - 1 que = deque([(init, 0)]) sell = [0] * (1 << (K << 1)) visited = [0] * (1 << (K << 1)) visited[init] = 1 while(que): v, b = que.pop() sell[v] = b b |= (v in st) 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 if(b == 1): que.append((nv, b)) continue que.appendleft((nv, b)) ans = sum(sell[k] for k in st) print(ans)