#include #include #include #include #define rep(i, l, r) for (int i = (l); i <= (r); i ++ ) #define per(i, r, l) for (int i = (r); i >= (l); i -- ) using namespace std; const int N = 3005, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; int n, m; double x[N][N], y[N][N], dis[N][N]; char ch[N][N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m; rep(i, 1, n) rep(j, 1, m) cin >> ch[i][j], x[i][j] = (i + j) * 1.0 / 2, y[i][j] = (i - j) * 1.0 / 2; queue > q; rep(i, 1, n) rep(j, 1, m) if (ch[i][j] == '.') q.push({i, j}), dis[i][j] = 0; else dis[i][j] = 1e9; rep(i, 0, n + 1) rep(j, 0, m + 1) if (i == 0 || j == 0 || i == n + 1 || j == m + 1) q.push({i, j}), x[i][j] = (i + j) * 1.0 / 2, y[i][j] = (i - j) * 1.0 / 2; while (!q.empty()) { auto t = q.front(); q.pop(); for (int i = 0; i < 4; i ++ ) { int nx = t.first + dx[i], ny = t.second + dy[i]; if (nx < 0 || ny < 0 || nx > n + 1 || ny > m + 1) continue; if (dis[nx][ny] > dis[t.first][t.second] + fabs(x[nx][ny] - x[t.first][t.second]) + fabs(y[nx][ny] - y[t.first][t.second])) { dis[nx][ny] = dis[t.first][t.second] + fabs(x[nx][ny] - x[t.first][t.second]) + fabs(y[nx][ny] - y[t.first][t.second]); q.push({nx, ny}); } } } double ans = 0; rep(i, 1, n) rep(j, 1, m) ans = max(ans, dis[i][j]); cout << (int)ans << '\n'; return 0; }