#include using namespace std; /* * * 全ての性能において上回っている魔道具のみ残す * */ int main() { int n, k; cin >> n >> k; vector s(n); int sz = 1; for (int i = 0; i < k; i++) sz *= 5; vector result(sz, false); vector exist(sz, false); vector use(sz, -1); for (int i = 0; i < n; i++) { string t; cin >> t; int state = 0; int now = 1; for (int j = 0; j < k; j++) { state += now * (t[j] - '0'); now *= 5; } s[i] = state; exist[state] = true; } auto i2s = [&k](int state) { string t; for (int i = 0; i < k; i++) { t.push_back((char)((state % 5) + '0')); state /= 5; } return t; }; function f = [&](int state) -> bool { if (sz <= state) { return false; } if (use[state] != -1) { return result[state]; } string t = i2s(state); bool flag = false; int now = 1; for (int i = 0; i < k; i++) { if (t[i] - '0' < 4) { flag |= f(state + now); } now *= 5; } result[state] = flag; use[state] = 0; if (!flag && exist[state]) { result[state] = true; use[state] = 1; } return result[state]; }; f(0); int ans = n; for (int i = 0; i < sz; i++) { if (use[i] == 1) ans--; } cout << ans << endl; }