class cum2:
    def __init__(self, A):
        self.cum = [[0]*(len(A[0])+1) for _ in range(len(A)+1)]
        for i in range(len(A)):
            for j in range(len(A[0])):
                self.cum[i+1][j+1] = A[i][j]
        for i in range(1, len(A)+1):
            for j in range(2, len(A[0])+1):
                self.cum[i][j] += self.cum[i][j-1]
        for i in range(2, len(A)+1):
            for j in range(1, len(A[0])+1):
                self.cum[i][j] += self.cum[i-1][j]
    def query(self, lh, lw, rh, rw):
        return self.cum[rh+1][rw+1]+self.cum[lh][lw]-self.cum[rh+1][lw]-self.cum[lh][rw+1]

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

def func(n):
    imos = [[0]*(W+1) for _ in range(H+1)]
    for i in range(H-n+1):
        for j in range(W-n+1):
            if cum.query(i, j, i+n-1, j+n-1) == n**2:
                imos[i][j] += 1
                imos[i+n][j+n] += 1
                imos[i][j+n] -= 1
                imos[i+n][j] -= 1
    for i in range(H+1):
        for j in range(1, W+1):
            imos[i][j] += imos[i][j-1]
    for i in range(1, H+1):
        for j in range(W+1):
            imos[i][j] += imos[i-1][j]
    imos.pop()
    for i in range(H):
        for j in range(W):
            if 1 <= imos[i][j]:
                imos[i][j] = "#"
            else:
                imos[i][j] = "."
        imos[i].pop()
    flag = imos == S
    del imos
    return flag

C = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            C[i][j] = 1
cum = cum2(C)
del C

left = 1
right = min(H, W)+1
while left+1 < right:
    mid = (left+right)//2
    if func(mid):
        left = mid
    else:
        right = mid

print(left)