from collections import deque import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) H, W = map(int, input().split()) G = [[0] * (W + 1) for _ in range(H + 1)] for i in range(1, H + 1): for j, v in enumerate(input().rstrip(), 1): if v == "#": G[i][j] = -1 for i in range(1, H + 1): for j in range(1, W + 1): if G[i][j] == -1: G[i][j] = min(G[i-1][j], G[i][j-1], G[i-1][j-1]) + 1 ans = max(max(g) for g in G) print((ans + 1) // 2)