#include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; constexpr i64 mod = 1e9 + 7; using vi = vector; using vvi = vector; using ii = pair; using vii = vector; stack yusho[10]; int yushoval[10]; int yushonum[101010]; int cnt = 0; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int r; for (int j = 0; j < m; j++) { cin >> r; if (yusho[j].empty()) { yushoval[j] = r; yusho[j].push(i); if (yushonum[i] == 0) { cnt++; } yushonum[i]++; } else if (yushoval[j] < r) { yushoval[j] = r; while (yusho[j].size()) { int k = yusho[j].top(); yusho[j].pop(); yushonum[k]--; if (yushonum[k] == 0) { cnt--; } } if (yushonum[i] == 0) { cnt++; } yusho[j].push(i); yushonum[i]++; } else if (yushoval[j] == r) { yusho[j].push(i); if (yushonum[i] == 0) { cnt++; } yushonum[i]++; } } cout << cnt << endl; } }