#include <iostream>
using namespace std;
int main()
{
int i, j, k, R, C;
int ok, n = 0;
cin >> R >> C;
int S[R+2][C+2]={0};
int flag[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
for (i=1;i<=R;i++)
for (j=1;j<=C;j++)
cin >> S[i][j];
for (i=1;i<=R;i++)
for (j=1;j<=C;j++) {
ok = 0;
for (k=0;k<8;k++)
if (S[i][j] == S[i+flag[k][0]][j+flag[k][1]])
ok = 1;
if (ok == 0)
n++;
}
cout << n;
}