H,W = map(int,raw_input().split()) assert 1 <= H <= 3000 assert 1 <= W <= 3000 S = [raw_input() for i in xrange(H)] for i in xrange(H): assert len(S[i]) == W assert S[i].count("#")+S[i].count(".") == W HD = [[W]*(W+2) for i in xrange(H+2)] VD = [[H]*(W+2) for i in xrange(H+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] == ".": HD[i][j] = VD[i][j] = 0 for i in xrange(1,H+1): for j in xrange(1,H+1): HD[i][j] = 1 + min(HD[i][j]-1,HD[i-1][j-1],HD[i][j-1],HD[i+1][j-1]) VD[i][j] = 1 + min(VD[i][j]-1,VD[i-1][j-1],VD[i-1][j],VD[i-1][j+1]) for i in xrange(H,0,-1): for j in xrange(W,0,-1): HD[i][j] = 1 + min(HD[i][j]-1,HD[i+1][j+1],HD[i][j+1],HD[i-1][j+1]) VD[i][j] = 1 + min(VD[i][j]-1,VD[i+1][j+1],VD[i+1][j],VD[i+1][j-1]) ans = 0 for i in xrange(1,H+1): for j in xrange(1,W+1): ans = max(ans,min(HD[i][j],VD[i][j])) print ans