#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" #define REP(i,a,b) for(i=a;i> a;}; template void reader(T& t, U& u) { reader(t); reader(u); } template void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); } void writer(const int a, char c) { printf("%d", a); putchar(c); } void writer(const ll a, char c) { printf("%lld", a); putchar(c); } void writer(const ull a, char c) { printf("%llu", a); putchar(c); } void writer(const double a, char c) { printf("%.20lf", a); putchar(c); } void writer(const char a[]) { printf("%s", a); }; void writer(const char a[], char c) { printf("%s", a); putchar(c); }; void writer(const char a, char c) { putchar(a); putchar(c); }; template void writerLn(T t) { writer(t, '\n'); } template void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); } template void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); } template void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); } template void writerVec(vector x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); } vector split(const string &str, char sep) { vector v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; } // #define int ll bool test = 0; int dx[] = { 0,1,0,-1 }; int dy[] = { 1,0,-1,0 }; #define INF (1 << 28) ull mod = (int)1e9 + 7; //..................... #define MAX (int)1e6 + 5 char field[3005][3005]; int fieldv[3005][3005]; int H, W; struct Point { int y, x, cnt; }; void grid_bfs() { int i, j; Point s; //............. queue q; cin >> H >> W; REP(i, 1, H + 1) { char buf[3005]; reader(buf); field[i][0] = ' '; strcpy(field[i] + 1, buf); } rep(i, H + 1) rep(j, W + 1) fieldv[i][j] = INF; REP(i, 1, H+1) REP(j, 1, W+1) { char c = field[i][j]; if (c == '.') { q.push({ i,j,0 }); fieldv[i][j] = 0; } } rep(i, H+2) { fieldv[i][0] = 0; q.push({ i,0,0 }); } rep(i, H+2) { fieldv[i][W + 1] = 0; q.push({ i,W + 1,0 }); } rep(i, W+2) { fieldv[0][i] = 0; q.push({ 0,i,0 }); } rep(i, W+2) { fieldv[H + 1][i] = 0; q.push({ H + 1,i,0 }); } //.............. while (q.size()) { auto now = q.front(); q.pop(); Point next = now; next.cnt++; REP(i,-1,2) REP(j,-1,2) { next.x = now.x + i; next.y = now.y + j; if (next.x < 0 || W + 1 <= next.x) continue; if (next.y < 0 || H + 1 <= next.y) continue; if (fieldv[next.y][next.x] > next.cnt) { fieldv[next.y][next.x] = next.cnt; q.push(next); } } } } signed main(void) { int i, j, k, l; grid_bfs(); int a = 0; rep(i, H + 1) rep(j, W + 1) { if (fieldv[i][j] > a) a = fieldv[i][j]; } cout << a << endl; //rep(i, H + 2) { // rep(j, W + 2) { // cout << fieldv[i][j] << " "; // } // cout << endl; //} return 0; }