# https://yukicoder.me/problems/no/2456 def solve(H, W, S, replica_cells, k): stamped_cell = [[0] * (W + 1) for _ in range(H + 1)] for h in range(k, H + 1): for w in range(k, W + 1): b = replica_cells[h][w] - replica_cells[h - k][w] - replica_cells[h][w - k] + replica_cells[h - k][w - k] if b == k ** 2: stamped_cell[h][w] += 1 stamped_cell[h - k][w] -= 1 stamped_cell[h][w - k] -= 1 stamped_cell[h - k][w - k] += 1 for h in range(H + 1): ans = 0 for w in reversed(range(W + 1)): ans += stamped_cell[h][w] stamped_cell[h][w] = ans for w in range(W + 1): ans = 0 for h in reversed(range(H + 1)): ans += stamped_cell[h][w] stamped_cell[h][w] = ans for h in range(H): for w in range(W): if S[h][w] == "#" and stamped_cell[h + 1][w + 1] == 0: return False elif S[h][w] == "." and stamped_cell[h + 1][w + 1] > 0: return False return True def main(): H, W = map(int, input().split()) S = [] for _ in range(H): S.append(input()) replica_cells = [[0] * (W + 1) for _ in range(H + 1)] for h in range(H): for w in range(W): if S[h][w] == "#": replica_cells[h + 1][w + 1] = 1 for h in range(H): row = 0 for w in range(W): row += replica_cells[h + 1][w + 1] replica_cells[h + 1][w + 1] = row + replica_cells[h][w + 1] low = 1 high = min(H, W) while high - low > 1: mid = (high + low) // 2 if solve(H, W, S, replica_cells, mid): low = mid else: high =mid if solve(H, W, S, replica_cells, high): print(high) else: print(low) if __name__ == "__main__": main()