#include #define MOD 1000000007 using namespace std; typedef long long ll; typedef pair ii; #include #include #include #include using namespace std; typedef long long ll; typedef pair ii; int dir[8][2] = {{1,1},{1,-1},{-1,1},{-1,-1},{1,0},{-1,0},{0,1},{0,-1}}; int n,m; bool isok(int a,int b){ return a>=0 && a<=n+1 && b>=0 && b<=m+1; } int r[3003][3003]; int main() { memset(r,-1,sizeof(r)); ios::sync_with_stdio(false); queue bfs; cin>>n>>m; string t; for(int ctr1=0;ctr1<=m+1;ctr1++) bfs.push({0,ctr1}),r[0][ctr1]=0; for(int ctr1=1;ctr1<=n;ctr1++){ bfs.push({ctr1,0}),r[ctr1][0]=0; cin>>t; for(int ctr2=0;ctr2