const int di[]={-1, 0, 1, 0},
dj[]={ 0, 1, 0,-1};
void fill(int i, int j)
{
if(i <= 0 || j <= 0 || i > n || j > m || M[i][j] != 1) return;
M[i][j] = 2;
for(int k = 0; k < 4; k++)
fill(i+di[k], j+dj[k]);
}
const int di[]={-1, 0, 1, 0},
dj[]={ 0, 1, 0,-1};
void fill(int i, int j)
{
if(i <= 0 || j <= 0 || i > n || j > m || M[i][j] != 1) return;
M[i][j] = 2;
for(int k = 0; k < 4; k++)
fill(i+di[k], j+dj[k]);
}