#include #include #include #include using namespace std; using vi = vector; #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) int main() { int N, M; cin >> N >> M; vector> R(N, vi(M)); rep(i, N) { rep(j, M) { cin >> R[i][j]; } } vi max_R(N, 0); vector maxes(N, vi()); multiset ans; rep(k, N) { rep(j, M) { if (max_R[j] > R[k][j]) continue; if (max_R[j] == R[k][j]) { ans.insert(k); maxes[j].push_back(k); continue; } while (!maxes[j].empty()) { int v = maxes[j].back(); maxes[j].pop_back(); ans.erase(ans.lower_bound(v)); } ans.insert(k); maxes[j].push_back(k); max_R[j] = R[k][j]; } set st; for (const auto& e:ans) st.insert(e); cout << st.size() << endl; } return 0; }