#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define watch(a) { cout << #a << " = " << a << endl; } template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int const inf = 1<<29; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; template constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y> H >> W; cin.ignore(); rep(i, H + 2) rep(j, W + 2) { G[i][j] = '.'; } rep(i, H) { rep(j, W) { scanf("%c", &(G[i+1][j+1])); } cin.ignore(); } H += 2, W += 2; /* rep(i, H) { rep(j, W) { printf("%c", G[i][j]); } puts(""); } //*/ vector> v; rep(i, H) rep(j, W) if(G[i][j] == '.') { rep(k, 4) { int ni = i + dy[k], nj = j + dx[k]; if(!in_range(ni, nj, H, W)) continue; if(G[ni][nj] == '#') { v.emplace_back(i, j); } } } sort(all(v)); v.erase(unique(all(v)), v.end()); // for(auto && e: v) { cout << e.first << ", " << e.second << endl; } int ans = 0; rep(i, H) rep(j, W) { if(G[i][j] == '#') { int mn = inf; for(auto && e: v) { mn = min(mn, max(abs(e.first - i), abs(e.second - j))); } ans = max(mn, ans); } } cout << ans << endl; return 0; }