#include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; template using V = vector; int N, K; V > G; struct MagicItem{ int vec[11] = { 0 }; }; int comp(const void* v1, const void* v2) { bool flag = true; rep(i, 0, K) { if (((MagicItem*)v1)->vec[i] == ((MagicItem*)v2)->vec[i]) { continue; } flag = false; break; } if (flag) { return 0; } flag = true; rep(i, 0, K) { if (((MagicItem*)v1)->vec[i] <= ((MagicItem*)v2)->vec[i]) { continue; } flag = false; break; } if (flag) { G[((MagicItem*)v1)->vec[K]].push_back(((MagicItem*)v2)->vec[K]); return -1; } flag = true; rep(i, 0, K) { if ((((MagicItem*)v1)->vec[i] >= ((MagicItem*)v2)->vec[i])) { continue; } flag = false; break; } if (flag) { G[((MagicItem*)v2)->vec[K]].push_back(((MagicItem*)v1)->vec[K]); return 1; } return 1; } int main(void) { cin >> N >> K; MagicItem* A = (MagicItem*)malloc(sizeof(MagicItem) * N); V > graph(N, V({})); G = graph; rep(i, 0, N) { MagicItem mit = MagicItem(); rep(j, 0, K) { cin >> mit.vec[j]; } mit.vec[K] = i; A[i] = mit; } qsort(A, N, sizeof(MagicItem), comp); int ans = 0; for (auto v : G) { ans += (v.size() > 0); } cout << ans << endl; return 0; }