############################################################# import sys sys.setrecursionlimit(10**7) from heapq import heappop,heappush from collections import deque,defaultdict,Counter from bisect import bisect_left, bisect_right from itertools import product,combinations,permutations ipt = sys.stdin.readline def iin(): return int(ipt()) def lmin(): return list(map(int,ipt().split())) MOD = 998244353 ############################################################# N,M = lmin() S = [input() for _ in range(N)] S = [[0 if S[i][j] == "." else 1 for j in range(M)] for i in range(N)] T = [[0]*(M+1) for _ in range(N+1)] for i in range(N): for j in range(M): T[i+1][j+1] = T[i][j+1]+T[i+1][j]-T[i][j]+S[i][j] def check(x): cnt = [[0]*(M+2) for _ in range(N+2)] for i in range(N-x+1): for j in range(M-x+1): #print(i,j,T[i+x+1][j+x+1]-T[i][j+x+1]-T[i+x+1][j]+T[i][j]) if T[i+x][j+x]-T[i][j+x]-T[i+x][j]+T[i][j] == x**2: cnt[i+1][j+1] += 1 cnt[i+1][j+x+1] -= 1 cnt[i+x+1][j+1] -= 1 cnt[i+x+1][j+x+1] += 1 #print(cnt) for i in range(1,N+1): for j in range(1,M+1): cnt[i][j] += cnt[i][j-1] for i in range(1,N+1): for j in range(1,M+1): cnt[i][j] += cnt[i-1][j] #print(x,cnt) for i in range(1,N+1): for j in range(1,M+1): if S[i-1][j-1] and not cnt[i][j]: return False return True ok = 1 ng = min(N,M)+1 while ng-ok > 1: cen = (ok+ng)//2 if check(cen): ok = cen else: ng = cen print(ok)