// #pragma region header #include using namespace std; // #include // using namespace atcoder; // clang-format off /* alias */ using ull = unsigned long long; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vll = vector; using vd = vector; using vs = vector; using vb = vector; using vpii = vector>; using vpll = vector>; using vvi = vector>; using vvll = vector>; using vvd = vector>; using vvs = vector>; using vvb = vector>; template using min_priority_queue = priority_queue, greater>; /* define */ #define MOD 998244353 // #define MOD 1000000007 #define INF (1LL << 60) #define inf (1 << 28) #define elif else if #define pb push_back #define pf push_front #define fi first #define se second #define all(obj) (obj).begin(), (obj).end() #define YESNO(bool) cout << (bool ? "YES\n" : "NO\n") #define YesNo(bool) cout << (bool ? "Yes\n" : "No\n") #define yesno(bool) cout << (bool ? "yes\n" : "no\n") template bool chmax(T &a, const T &b) {if(a bool chmin(T &a, const T &b) {if(b= 0; i--) #define rrepd(i, n) for(ll i = (n); i >= 1; i--) #define fore(i, a) for(auto &i: a) /* vector */ template T vmax(vector &array){ T ret = array[0]; for(T a: array) chmax(ret, a); return ret; } template T vmin(vector &array){ T ret = array[0]; for(T a: array) chmin(ret, a); return ret; } template T sum(vector &array){ T ret = 0; for(T a:array) ret += a; return ret; } template void list_set(vector &array){ sort(all(array)); array.erase(unique(all(array)),array.end()); } template T bisect_left(vector &array, T key){ return lower_bound(all(array),key) - array.begin(); } template T bisect_right(vector &array, T key){ return upper_bound(all(array),key) - array.begin(); } /* string */ ll string_to_ll(string n){ ll ret = 0, k = 1; while(n.length() > 0){ ret += k * (n.back() - '0'); n.pop_back(); k *= 10; } return ret; } string ll_to_string(ll n){ string ret = ""; while(n > 0){ ret.pb((n % 10) + '0'); n /= 10; } reverse(all(ret)); return ret; } struct popopo{ popopo(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } popopoppo; // n = 1,...,N に対して、n % A < B を満たすものの数 ll Count_of_n_mod_A_less_than_B(ll N, ll A, ll B){ return N / A * min(A, B) + min(N % A, B - 1); } /* IN/OUT */ int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(string &a) { cin >> a; } template void scan(pair &p) { scan(p.first), scan(p.second); } template void scan(vector &); template void scan(vector &a) { for(auto &i : a) scan(i); } void IN(){} template void IN(Head& head, Tail &...tail){ scan(head); IN(tail...); } #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define VEC(type, name, size) vector name(size); IN(name) #define VECS(type, name, size) vector name(size + 1); for(int i = 1; i <= size; i++) scan(name[i]) void OUT(){ cout << "\n"; } template void output(T a){ cout << a; } template void output(vector v){ for(int i = 0; i < v.size(); i++) cout << v[i] << (i == v.size() - 1 ? "" : " "); } template void OUT(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; OUT(tail...); } void FLASH(){ cout << endl; } template void FLASH(const Head &head, const Tail &...tail) { output(head); if(sizeof...(tail)) cout << " "; FLASH(tail...); } // clang-format on // #pragma endregion header // A: Rustで書いたらCE食らって泣いた // B: 一生わからなかった、これすぐ解けないのダメすぎ // C: a \neq b を見逃していました... それ以外はやるだけ struct UnionFind { vector par; vector siz; int sz; UnionFind(int n) : par(n), siz(n, 1), sz(n) { for (int i = 0; i < n; i++) { par[i] = i; } } int root(int x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; sz--; } int size(int x) { return siz[root(x)]; } int size() { return sz; } }; int main() { LL(N, K); vvll S(N); rep(i, N) { STR(s); for (auto c : s) { S[i].pb(c - '0'); } } // ll N = 200000; // ll K = 8; // vvll S(N, vll(K, 0)); // rep(i, N) rep(j, K) { // S[i][j] = rand() % 5; // } UnionFind uf(N); rep(i, N) { rep(j, N) if (i != j) { if ([&]() { rep(k, K) if (S[i][k] > S[j][k]) return false; return true; }()) { uf.unite(i, j); break; } } } OUT(N - uf.size()); }