#include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) #define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); itr++) 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; set st = {}; rep(i, 0, N) { string s; cin >> s; st.insert(toNum(s)); } set visited = {}; itrep(itr, st) { int sv = *itr; if (visited.find(sv) != visited.end()) { 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.find(nv) != visited.end()) { continue; } visited.insert(nv); stk.push_back(nv); } } } int ans = 0; itrep(itr, st) { if (visited.find(*itr) == visited.end()) { continue; } ans++; } cout << ans << endl; return 0; }