#include <iostream>
#define Unknown 1001
using namespace std;
int main() {
int n, m,uf = 0,maxi;
//input
cin >> n >> m;
int ** x = new int * [n];
for (int i = 0; i < n; i++)
x[i] = new int[m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> x[i][j];
//workspace
int max[m];
for (int i = 0; i < m; i++){
max[i] = Unknown;
}
for (int i = 0; i < n; i++) {
int min = x[i][0];
for (int j = 1; j < m; j++) {
if ( min > x[i][j] ) {
min = x[i][j];
}
}
for (int j = 0; j < m; j++) {
if (x[i][j] == min) {
if (max[j] != Unknown){
maxi = max[j];
}
else {
maxi = x[i][j];
for (int l = 0; l < n; l++) {
if (maxi < x[l][j]){
maxi = x[l][j];
}
}
max[j] = maxi;
}
if ( maxi == min) {
uf++;
}
}
}
}
//output
cout << uf;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIFVua25vd24gMTAwMQp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbiwgbSx1ZiA9IDAsbWF4aTsKCS8vaW5wdXQKCWNpbiA+PiBuID4+IG07CglpbnQgKiogeCA9IG5ldyBpbnQgKiBbbl07Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQl4W2ldID0gbmV3IGludFttXTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSAKCQlmb3IgKGludCBqID0gMDsgaiA8IG07IGorKykgCgkJCWNpbiA+PiB4W2ldW2pdOwoJLy93b3Jrc3BhY2UKCWludCAgbWF4W21dOwoJZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspewoJCW1heFtpXSA9IFVua25vd247CQoJfQoJZm9yIChpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKCQlpbnQgbWluID0geFtpXVswXTsKCQlmb3IgKGludCBqID0gMTsgaiA8IG07IGorKykgewoJCQlpZiAoIG1pbiA+IHhbaV1bal0gKSB7CgkJCQltaW4gPSB4W2ldW2pdOwoJCQ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