20250711
//#include<stdio.h>
//int n, m,q[1000005][2]={}, top=-1,b=-1,i,j,arr[1005][1005]={},k=1,cnt=0;
//int main()
//{
// scanf("%d %d", &m, &n);
// for(i=0;i<=n+1;i++)
// {
// for(j=0;j<=m+1;j++)
// {
// if (i<1 || j<1 || i>n || j>m)
// {
// arr[i][j]=-1;
// }
// else
// {
// scanf("%d", &arr[i][j]);
// if (arr[i][j]==1)
// {
// top++;
// q[top][0]=i;
// q[top][1]=j;
// }
// }
// }
// }
// while(top!=b)
// {
// cnt ++;
// int max = top;
// for(i=b+1;i<=max;i++)
// {
// b++;
// int y=q[b][0];
// int x=q[b][1];
// if (arr[y+1][x]!=-1 && arr[y+1][x]!=1)
// {
// arr[y+1][x]=1;
// top++;
// q[top][0]=y+1;
// q[top][1]=x;
// }
// if (arr[y-1][x]!=-1 && arr[y-1][x]!=1)
// {
// arr[y-1][x]=1;
// top++;
// q[top][0]=y-1;
// q[top][1]=x;
// }
// if (arr[y][x+1]!=-1 && arr[y][x+1]!=1)
// {
// arr[y][x+1]=1;
// top++;
// q[top][0]=y;
// q[top][1]=x+1;
// }
// if (arr[y][x-1]!=-1 && arr[y][x-1]!=1)
// {
// arr[y][x-1]=1;
// top++;
// q[top][0]=y;
// q[top][1]=x-1;
// }
// }
//// for(i=0;i<=n+1;i++)
//// {
//// for(j=0;j<=m+1;j++)
//// {
//// printf("%2d ", arr[i][j]);
//// }
//// printf("\n");
//// }
//// printf("\n\n%d\n", cnt);
// }
// for(i=1;i<=n;i++)
// {
// for(j=1;j<=m;j++)
// {
// if (arr[i][j]==0)
// {
// printf("-1");
// return 0;
// }
// }
// }
// printf("%d", cnt-1);
// return 0;
//}




