#include #include #include #define rep(i, l, n) for (int i = (l); i < (n); i++) using namespace std; template using V = vector; int main(void) { int N, K; cin >> N >> K; V > A(N, V(K)); rep(i, 0, N) { rep(j, 0, K) { cin >> A[i][j]; } } if (K == 1) { cout << (N - 1) << endl; return 0; } V local_max(N); rep(i, 0, K - 1) { rep(j, i + 1, K) { V > vec(N, V(3)); rep(k, 0, N) { vec[k] = { A[k][i],A[k][j],k }; } sort(vec.begin(), vec.end(), greater >()); int ma = vec[0][1]; local_max[vec[0][2]] = (vec[0][0] > vec[1][0] or vec[0][1] > vec[1][1]); for (auto v : vec) { int a = v[0], b = v[1], c = v[2]; if (b <= ma) { continue; } local_max[c] = true; ma = b; } } } int ans = 0; for (auto lm : local_max) { ans += lm ^ 1; } cout << ans << endl; return 0; }