def oi(): return int(input()) def os(): return input() def mi(): return list(map(int, input().split())) H, W = mi() S = [os() for _ in range(H)] v = [[0 for i in range(H+1)] for j in range(W+1)] for i in range(1, H+1): for j in range(1, W+1): if S[i-1][j-1] == '#': v[i][j]+=1 v[i][j] += v[i-1][j] + v[i][j-1] - v[i-1][j-1] def solve(X): w = [[0 for i in range(H+2)] for j in range(W+2)] for i in range(1, H-X+2): for j in range(1, W-X+2): if v[i+X-1][j+X-1]-v[i+X-1][j-1]-v[i-1][j+X-1]+v[i-1][j-1] == X*X: w[i][j]+=1 w[i+X][j]-=1 w[i][j+X]-=1 w[i+X][j+X]+=1 for i in range(0, H+2): for j in range(1, W+2): w[i][j] += w[i][j-1] for i in range(1, H+2): for j in range(0, W+2): w[i][j] += w[i-1][j]; for i in range(1, H+1): for j in range(1, W+1): if S[i-1][j-1] == '#' and w[i][j] == 0: return 0 return 1 l=1 r=min(H, W)+1 while(r-l>1): c = (l+r)//2 if solve(c): l=c else: r=c; print(l)