#include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; template using V = vector; int toNum(string s) { int ret = 0; rep(i, 0, s.size()) { char c = s[i]; ret |= (3 - (c - 'A')) << (i << 1); } return ret; } int main(void) { int N, K; cin >> N >> K; V mag(N); rep(i, 0, N) { string s; cin >> s; mag[i] = toNum(s); } V visited(1 << (K << 1)); for (int sv : mag) { if (visited[sv] == true) { continue; } V stk = { sv }; while (stk.empty() == false) { int v = stk[stk.size() - 1]; stk.pop_back(); rep(i, 0, K) { int k = i << 1; if (((v >> k) & 3) == 0) { continue; } int nv = v - (1 << k); if (visited[nv] == true) { continue; } visited[nv] = true; stk.push_back(nv); } } } int ans = 0; for (int v : mag) { if (visited[v] == false) { continue; } ans++; } cout << ans << endl; return 0; }