H, W = map(int, input().split()) S = [input() for _ in range(H)] A = [[0] * (W + 1) for _ in range(H + 1)] for i in range(H): for j in range(W): if S[i][j] == '#': A[i + 1][j + 1] += 1 for i in range(H + 1): for j in range(W): A[i][j + 1] += A[i][j] for i in range(H): for j in range(W + 1): A[i + 1][j] += A[i][j] le = 1 ri = (min(H, W) + 1) // 2 while le + 1 < ri: mi = (le + ri) // 2 k = 2 * mi + 1 ok = False for i in range(H + 1 - k): for j in range(W + 1 - k): if A[i + k][j + k] - A[i][j + k] - A[i + k][j] + A[i][j] == k * k: ok = True if ok: le = mi else: ri = mi print(ri)