#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int m,n,count,x,y;
cin>>m>>n;
int A[m][n];
count=0;
for(x=0;x<m;x++)
{
for(y=0;y<n;y++)
{
cin>>A[x][y];
}
}
for(x=1;x<m-1;x++)
{
for(y=1;y<n-1;y++)
{
if(A[x][y]>A[x+1][y]&&A[x][y]>A[x-1][y]&&A[x][y]<A[x][y+1]&&A[x][y]<A[x][y-1])
{
count=count+1;
}
}
}
printf("%d\n",count);
}
#include<stdio.h>
using namespace std;
int main()
{
int m,n,count,x,y;
cin>>m>>n;
int A[m][n];
count=0;
for(x=0;x<m;x++)
{
for(y=0;y<n;y++)
{
cin>>A[x][y];
}
}
for(x=1;x<m-1;x++)
{
for(y=1;y<n-1;y++)
{
if(A[x][y]>A[x+1][y]&&A[x][y]>A[x-1][y]&&A[x][y]<A[x][y+1]&&A[x][y]<A[x][y-1])
{
count=count+1;
}
}
}
printf("%d\n",count);
}