#include <iostream>
using namespace std;
int main() {
int r, c, w = 0, a, b, l, d;
cin >> r >> c;
int **x = new int * [r];
for (int i = 0; i < r; i++) x[i] = new int[c];
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
cin >> x[i][j];
}
}
for (int i = 0; i < r; i++){
for (int j = 0; j < c; j++){
a = b = l = d = 1;
for (int q = 0; q < i; q++){
if (x[i][j] <= x[q][j])
a = 0;
}
for (int q = i+1; q < r; q++){
if (x[i][j] <= x[q][j])
b = 0;
}
for (int k = 0; k < j; k++){
if (x[i][j] <= x[i][k])
l = 0;
}
for (int k = j+1; k < c; k++){
if (x[i][j] <= x[i][k])
d = 0;
}
w+= a + b + l + d;
}
}
cout << w;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IHIsIGMsIHcgPSAwLCBhLCBiLCBsLCBkOwogICAgY2luID4+IHIgPj4gYzsKICAgIGludCAqKnggPSBuZXcgaW50ICogW3JdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCByOyBpKyspIHhbaV0gPSBuZXcgaW50W2NdOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCByOyBpKyspewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgYzsgaisrKXsKICAgICAgICAgICAgY2luID4+IHhbaV1bal07CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCByOyBpKyspewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgYzsgaisrKXsKICAgICAgICAgICAgYSA9IGIgPSBsID0gZCA9IDE7CiAgICAgICAgZm9yIChpbnQgcSA9IDA7IHEgPCBpOyBxKyspewogICAgICAgICAgICBpZiAoeFtpXVtqXSA8PSB4W3FdW2pdKQogICAgICAgICAgICAgICAgYSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IHEgPSBpKzE7IHEgPCByOyBxKyspewogICAgICAgICAgICBpZiAoeFtpXVtqXSA8PSB4W3FdW2pdKQogICAgICAgICAgICAgICAgYiA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGsgPSAwOyBrIDwgajsgaysrKXsKICAgICAgICAgICAgaWYgKHhbaV1bal0gPD0geFtpXVtrXSkKICAgICAgICAgICAgICAgIGwgPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBrID0gaisxOyBrIDwgYzsgaysrKXsKICAgICAgICAgICAgaWYgKHhbaV1bal0gPD0geFtpXVtrXSkKICAgICAgICAgICAgICAgIGQgPSAwOwogICAgICAgIH0KICAgICAgICB3Kz0gYSArIGIgKyBsICsgZDsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IHc7CiAgICByZXR1cm4gMDsKfQ==