#include using namespace std; const int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 }; const int dy[] = { 1, 0, -1, 0, -1, 1, -1, 1 }; int in_range( int h, int w, int x, int y ){ return 0 <= x and x < h and 0 <= y and y < w; } signed main(){ int H, W; cin >> H >> W; vector< string > G( H ); for( int i = 0; i < H; ++i ) cin >> G[ i ]; vector< string > _G( H + 2 ); for( int i = 0; i < W + 2; ++i ) _G[ 0 ] += ".", _G[ H + 1 ] += "."; for( int i = 1; i <= H; ++i ) _G[ i ] = "." + G[ i - 1 ] + "."; swap( G, _G ); H += 2, W += 2; queue< tuple< int, int, int > > que; vector< vector< int > > vis( H, vector< int >( W ) ); for( int i = 0; i < H; ++i ) for( int j = 0; j < W; ++j ) if( G[ i ][ j ] == '.' ) que.emplace( 0, i, j ), vis[ i ][ j ] = 1; int ans = 0; while( not que.empty() ){ int d, x, y; tie( d, x, y ) = que.front(); que.pop(); ans = max( ans, d ); for( int di = 0; di < 8; ++di ){ int nx = x + dx[ di ]; int ny = y + dy[ di ]; if( not in_range( H, W, nx, ny ) ) continue; if( vis[ nx ][ ny ] ) continue; vis[ nx ][ ny ] = 1; que.emplace( d + 1, nx, ny ); } } cout << ans << endl; return 0; }