#include <iostream>
#define N 750
using namespace std;
int main() {
int n, m, MIN[N], MAX[N];
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int input;
cin >> input;
if (i == 0) MAX[j] = input;
else if (MAX[j] < input) MAX[j] = input;
if (j == 0) MIN[i] = input;
else if (MIN[i] > input) MIN[i] = input;
}
}
int count = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (MIN[i] == MAX[j]) count++;
cout << count;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIE4gNzUwCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCBuLCBtLCBNSU5bTl0sIE1BWFtOXTsKCWNpbiA+PiBuID4+IG07Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewoJCWZvciAoaW50IGogPSAwOyBqIDwgbTsgaisrKSB7CgkJCWludCBpbnB1dDsKCQkJY2luID4+IGlucHV0OwoJCQlpZiAoaSA9PSAwKSBNQVhbal0gPSBpbnB1dDsKCQkJZWxzZSBpZiAoTUFYW2pdIDwgaW5wdXQpIE1BWFtqXSA9IGlucHV0OwoJCQlpZiAoaiA9PSAwKSBNSU5baV0gPSBpbnB1dDsKCQkJZWxzZSBpZiAoTUlOW2ldID4gaW5wdXQpIE1JTltpXSA9IGlucHV0OwoJCX0KCX0KCWludCBjb3VudCA9IDA7Cglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQlmb3IgKGludCBqID0gMDsgaiA8IG07IGorKykKCQkJaWYgKE1JTltpXSA9PSBNQVhbal0pIGNvdW50Kys7Cgljb3V0IDw8IGNvdW50OwoJcmV0dXJuIDA7Cn0=