h, w = map(int, input().split()) s = [input() for _ in range(h)] v = [[0] * (w + 1) for _ in range(h + 1)] for i in range(h): for j in range(w): if s[i][j] == '#': v[i + 1][j + 1] += 1 v[i + 1][j + 1] += v[i + 1][j] + v[i][j + 1] - v[i][j] def f(x): c = [[0] * (w + 2) for _ in range(h + 2)] for i in range(h - x + 1): for j in range(w - x + 1): if v[i + x][j + x] - v[i + x][j] - v[i][j + x] + v[i][j] == x * x: k, l = i + 1, j + 1 c[k][l] += 1 c[k + x][l] -= 1 c[k][l + x] -= 1 c[k + x][l + x] += 1 for i in range(h + 1): for j in range(w): c[i][j + 1] += c[i][j] for i in range(h): for j in range(w + 1): c[i + 1][j] += c[i][j] for i in range(h): for j in range(w): if s[i][j] == '#' and c[i + 1][j + 1] == 0: return 0 return 1 l = 1 r = min(h, w) + 1 while l + 1 < r: m = (l + r) // 2 if f(m): l = m else: r = m print(l)