#include #include #include using namespace std; #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) string S[3000]; int VD[3002][3002],HD[3002][3002]; int main(){ int H,W,MAX,ans = 0; scanf("%d %d",&H,&W); if ((H < 1)||(H > 3000)) throw "H is bad!"; if ((W < 1)||(W > 3000)) throw "W is bad!"; // rep(i,H){ // cin >> S[i]; // if(S[i].size() != W) throw "row size"; // rep(j,W){ // if((S[i][j] != '#') && (S[i][j] != '.')) throw "row element"; // } // } MAX = max(H,W); rep(i,H+2) rep(j,W+2){ if (i < 0 || i > H || j < 0 || j > W){ VD[i][j] = HD[j][i] = 0; } else{ VD[i][j] = HD[j][i] = (S[i-1][j-1] == '.' ? 0 : MAX); } } range(i,1,H+1) range(j,1,W+1) rep(k,3){ VD[i][j] = min(VD[i][j],VD[i-1][j-1+k]+1); VD[H+1-i][j] = min(VD[H+1-i][j],VD[H+2-i][j-1+k]+1); } range(j,1,W+1) range(i,1,H+1) rep(k,3){ HD[j][i] = min(HD[j][i],HD[j-1][i-1+k]+1); HD[W+1-j][i] = min(HD[W+1-j][i],HD[W+2-j][i-1+k]+1); } range(i,1,H+1) range(j,1,W+1){ ans = max(ans,min(VD[i][j],HD[j][i])); } printf("%d\n",ans); return 0; }