#include #define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr) using namespace std; int main(){ int N, K; cin >> N >> K; unordered_set st = {}; for(int i = 0; i < N; ++i){ string s; cin >> s; st.insert(s); } unordered_set visited = {}; itrep(itr, st){ string sv = *itr; if(visited.find(sv) != visited.end()){ continue; } vector stk = { sv }; while(!stk.empty()){ string v = stk[stk.size() - 1]; stk.pop_back(); for(int i = 0; i < K; ++i){ if(v[i] == '0'){ continue; } string nv = v; --nv[i]; 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; }