#include
#include
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int mat[a][b];
bool poseten[a][b];
queueQ;
for(int i=0;i>mat[i][j];
poseten[i][j]=false;
}
}
int kolku=0;
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};
for(int k=0;k<=a*b;k++)
{
int najmal=40;
int r=0,c=0;
for(int i=0;imat[i][j] && poseten[i][j]!=true)
{
najmal=mat[i][j];
r=i;
c=j;
}
}
}
if(najmal!=40)
{
poseten[r][c]=true;
Q.push(r);
Q.push(c);
kolku++;
while(!Q.empty())
{
int ci=Q.front();
Q.pop();
int cj=Q.front();
Q.pop();
for(int o = 0; o < 4; o++) {
int ti = ci + di[o];
int tj = cj + dj[o];
if(ti >= 0 and ti < a and tj >= 0 and tj < b and !poseten[ti][tj] and mat[ti][tj] >= mat[ci][cj]) {
poseten[ti][tj] = true;
Q.push(ti);
Q.push(tj);
}
}
}
}
}
cout<