/* package whatever; // don't place package name! */
import java.util.Scanner;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
int w = 0, a, b, l, d;
Scanner scan
= new Scanner
(System.
in); int r = scan.nextInt();
int c = scan.nextInt();
int[][] x = new int [r][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++){
x[i][j] = scan.nextInt();
}
}
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;
}
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCWludCB3ID0gMCwgYSwgYiwgbCwgZDsKCQlTY2FubmVyIHNjYW4gPSBuZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJCWludCByID0gc2Nhbi5uZXh0SW50KCk7CgkJaW50IGMgPSBzY2FuLm5leHRJbnQoKTsKCQlpbnRbXVtdIHggPSBuZXcgaW50IFtyXVtyXTsKCQlmb3IgKGludCBpID0gMDsgaSA8IH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