import numpy as np import sys input = sys.stdin.readline min1 = np.frompyfunc(lambda x, y: min(x, y) + 1, 2, 1) H, W = map(int, input().split()) dp = np.where(np.array([list(input()) for _ in range(H)]) == '.', 0, 1) reset = 1 - dp reset[:, 0] = 0 for h in range(1, H): dp[h, 1:] = np.minimum(dp[h - 1, :-1], dp[h - 1, 1:]) dp[h, np.where(reset[h])] = -1 min1.accumulate(dp[h], out=dp[h], dtype=np.object).astype(int) print((dp.max() + 1) // 2)