#include using namespace std; using int64 = long long; using uint64 = unsigned long long; constexpr int INF = (1 << 28); constexpr int MAX_N = 100000; constexpr int MAX_M = 10; int R[MAX_M][MAX_N], cumR[MAX_M][MAX_N + 1]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector deg(N, 0), maxR(M, 0); vector> tourists(M); int num = 0; for (int ni = 0; ni < N; ni++) { for (int mi = 0; mi < M; mi++) { int R; cin >> R; if (maxR[mi] > R) { continue; } else if (maxR[mi] < R) { maxR[mi] = R; while (!tourists[mi].empty()) { int t = tourists[mi].top(); tourists[mi].pop(); if (--deg[t] == 0) { num--; } } } tourists[mi].push(ni); if (++deg[ni] == 1) { num++; } } cout << num << '\n'; } return 0; }