def solve(): H,W = map(int,raw_input().split()) S = [] elem = {".","#"} for i in xrange(H): s = raw_input() assert len(s) == W assert len(elem | set(s)) == 2 S.append(s) VD = [[H]*(W+2) for i in xrange(H+2)] HD = [[W]*(H+2) for j in xrange(W+2)] for i in xrange(H+2): for j in xrange(W+2): if not (0 < i <= H and 0 < j <= W) or S[i-1][j-1] == ".": VD[i][j] = HD[j][i] = 0 for i in xrange(1,H+1): for j in xrange(1,W+1): VD[i][j] = 1 + min(VD[i][j]-1,VD[i-1][j-1],VD[i-1][j],VD[i-1][j+1]) VD[H+1-i][j] = 1 + min(VD[H+1-i][j]-1,VD[H+2-i][j-1],VD[H+2-i][j],VD[H+2-i][j+1]) for j in xrange(1,W+1): for i in xrange(1,H+1): HD[j][i] = 1 + min(HD[j][i]-1,HD[j-1][i-1],HD[j-1][i],HD[j-1][i+1]) HD[W+1-j][i] = 1 + min(HD[W+1-j][i]-1,HD[W+2-j][i-1],HD[W+2-j][i],HD[W+2-j][i+1]) ans = 0 for i in xrange(1,H+1): for j in xrange(1,W+1): ans = max(ans,min(VD[i][j],HD[j][i])) print ans solve()