You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.

We will repeatedly perform the following operation until all the squares are black:

* Every white square that shares a side with a black square, becomes black.



Find the number of operations that will be performed. The initial grid has at least one black square.

Constraints

* 1 \leq H,W \leq 1000
* A_{ij} is `#` or `.`.
* The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:


H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}


Output

Print the number of operations that will be performed.

Examples

Input

3 3
...
.#.
...


Output

2


Input

6 6
..#..#
......
..#..
......
.#....
....#.


Output

3

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
from collections import deque
from itertools import chain
(H, W) = map(int, input().split())
G = chain.from_iterable([[s == '#' for s in input()] for _ in range(H)])
dist = [0] * (H * W)
B = deque([i for (i, g) in enumerate(G) if g])
visited = set(B)
while B:
	vij = B.pop()
	for dij in (W, -W, 1, -1):
		nij = vij + dij
		if dij == 1 and (not nij % W) or (dij == -1 and (not (nij + 1) % W)) or (not 0 <= nij < H * W) or (nij in visited):
			continue
		visited.add(nij)
		dist[nij] = 1 + dist[vij]
		B.appendleft(nij)
print(max(dist))


from queue import deque

def main():
	(h, w) = map(int, input().split())
	grids = [False] * (w * h)
	dq = deque()
	for i in range(h):
		for (j, c) in enumerate(list(input().strip())):
			if c == '#':
				grids[i * w + j] = True
				dq.append((0, i, j))
	while dq:
		(cnt, i, j) = dq.popleft()
		for (dx, dy) in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
			if 0 <= i + dx < h and 0 <= j + dy < w and (not grids[(i + dx) * w + (j + dy)]):
				grids[(i + dx) * w + (j + dy)] = True
				dq.append((cnt + 1, i + dx, j + dy))
	print(cnt)
main()


import sys
import math
from collections import deque
input = sys.stdin.readline
(h, w) = map(int, input().split())
a = [list(map(str, input())) for _ in range(h)]
b = deque()
n = [-1] * (h * w)
p = ((1, 0), (-1, 0), (0, 1), (0, -1))
for x in range(h):
	for y in range(w):
		if a[x][y] == '#':
			b.append((x, y))
			n[x * w + y] = 0
while b:
	(x, y) = b.popleft()
	for idx in p:
		(s, t) = idx
		if 0 <= x + s < h and 0 <= y + t < w:
			if n[(x + s) * w + (y + t)] == -1:
				n[(x + s) * w + (y + t)] = n[x * w + y] + 1
				b.append((x + s, y + t))
print(max(n))


from collections import deque
(H, W) = map(int, input().split())
C = []
Q = deque()
dist = [[-1] * W for i in range(H)]
for i in range(H):
	s = list(input())
	yxidx = [(i, x) for (x, v) in enumerate(s) if v == '#']
	for (y, x) in yxidx:
		Q.append((y, x))
		dist[y][x] = 0
	C.append(s)
X = [1, 0, -1, 0]
Y = [0, -1, 0, 1]
while Q:
	(y, x) = Q.popleft()
	for i in range(4):
		nx = x + X[i]
		ny = y + Y[i]
		if 0 <= nx < W and 0 <= ny < H and (dist[ny][nx] == -1):
			dist[ny][nx] = dist[y][x] + 1
			Q.append((ny, nx))
ans = 0
for i in range(H):
	ans = max(ans, max(dist[i]))
print(ans)


import collections
(H, W) = map(int, input().split())
went = [[False] * W for i in range(H)]
queue = collections.deque()
for hoge in range(H):
	for (huga, t) in enumerate(input()):
		if t == '#':
			went[hoge][huga] = True
			queue.append([hoge, huga, 0])
while queue:
	(curx, cury, ct) = queue.popleft()
	for (dx, dy) in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
		(newx, newy) = (curx + dx, cury + dy)
		newct = ct + 1
		if 0 <= newx < H and 0 <= newy < W and (not went[newx][newy]):
			went[newx][newy] = True
			queue.append([newx, newy, newct])
print(ct)


import sys
input = sys.stdin.readline
(h, w) = map(int, input().split())
A = [[False] * (w + 2) for _ in range(h + 2)]
(chk, chk2) = ([], [])
for i in range(h):
	s = input()
	for j in range(w):
		A[i + 1][j + 1] = s[j] == '.'
		if s[j] == '#':
			chk.append((i + 1, j + 1))
ans = 0
d = ((1, 0), (0, 1), (-1, 0), (0, -1))
while chk:
	for (cx, cy) in chk:
		for (dx, dy) in d:
			if A[cx + dx][cy + dy] == True:
				chk2.append((cx + dx, cy + dy))
				A[cx + dx][cy + dy] = False
	if chk2:
		ans += 1
	chk = chk2
	chk2 = []
print(ans)


from collections import deque
(h, w) = map(int, input().split())
A = [list(input()) for _ in range(h)]
V = [[-1] * w for _ in range(h)]
que = deque([])
for (i, a) in enumerate(A):
	for (j, _a) in enumerate(a):
		if _a == '#':
			que.append([i, j])
			V[i][j] = 0
dhdw = [[-1, 0], [1, 0], [0, -1], [0, 1]]
while que:
	(nwh, nww) = que.popleft()
	for (dh, dw) in dhdw:
		if not (0 <= nwh + dh < h and 0 <= nww + dw < w):
			continue
		if V[nwh + dh][nww + dw] != -1:
			continue
		V[nwh + dh][nww + dw] = V[nwh][nww] + 1
		que.append([nwh + dh, nww + dw])
print(max(map(max, V)))


from collections import deque
(H, W) = map(int, input().split())
A = [input() for i in range(H)]
dxy = [(0, 1), (1, 0), (0, -1), (-1, 0)]
INF = 99999
dp = [[INF] * W for i in range(H)]
q = deque()
for (y, row) in enumerate(A):
	for (x, c) in enumerate(row):
		if c == '#':
			dp[y][x] = 0
			q.append((x, y))
while q:
	(x, y) = q.popleft()
	d = dp[y][x]
	for (dx, dy) in dxy:
		(nx, ny) = (x + dx, y + dy)
		if not 0 <= nx < W:
			continue
		if not 0 <= ny < H:
			continue
		if dp[ny][nx] <= d + 1:
			continue
		dp[ny][nx] = d + 1
		q.append((nx, ny))
print(max((max(row) for row in dp)))


from collections import deque
(H, W) = map(int, input().split())
A = [input() for i in range(H)]
X = [1, 0, -1, 0]
Y = [0, -1, 0, 1]
INF = 99999
dp = [[-1] * W for i in range(H)]
q = deque()
for (y, row) in enumerate(A):
	for (x, c) in enumerate(row):
		if c == '#':
			dp[y][x] = 0
			q.append((y, x))
while q:
	(y, x) = q.popleft()
	d = dp[y][x]
	for i in range(4):
		nx = x + X[i]
		ny = y + Y[i]
		if 0 <= nx < W and 0 <= ny < H and (dp[ny][nx] == -1):
			dp[ny][nx] = d + 1
			q.append((ny, nx))
ans = 0
for i in dp:
	ans = max(ans, max(i))
print(ans)


from collections import deque
(h, w) = map(int, input().split())
l = []
l.append('@' * (w + 2))
for i in range(h):
	l.append('@' + input() + '@')
l.append('@' * (w + 2))
q = deque()
p = [[-1 for i in j] for j in l]
for i in range(1, h + 1):
	for j in range(1, w + 1):
		if l[i][j] == '#':
			q.append([i, j])
			p[i][j] = 0
while len(q) > 0:
	(x, y) = q.popleft()
	for (i, j) in [[1, 0], [-1, 0], [0, -1], [0, 1]]:
		if l[x + i][y + j] == '.' and p[x + i][y + j] == -1:
			q.append([x + i, y + j])
			p[x + i][y + j] = p[x][y] + 1
a = 0
for i in p:
	for j in i:
		a = max(a, j)
print(a)


from collections import deque
(h, w) = map(int, input().split())
d = deque()
op = [[-1] * w for i in range(h)]
for i in range(h):
	s = input().rstrip()
	for j in range(len(s)):
		if s[j] == '#':
			d.append((i, j, 0))
			op[i][j] = 0
while d:
	(i, j, step) = d.popleft()
	for (i2, j2) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
		if 0 <= i2 < h and 0 <= j2 < w:
			if op[i2][j2] == -1:
				d.append((i2, j2, step + 1))
				op[i2][j2] = step + 1
print(max([max(op[i]) for i in range(h)]))


from collections import deque
(h, w) = map(int, input().split())
a = [input() for _ in range(h)]
dxy = [(0, 1), (1, 0), (-1, 0), (0, -1)]
inf = float('inf')
dp = [[inf] * w for _ in range(h)]
q = deque()
for (y, l) in enumerate(a):
	for (x, c) in enumerate(l):
		if c == '#':
			dp[y][x] = 0
			q.append((x, y))
ans = 0
while q:
	(x, y) = q.popleft()
	d = dp[y][x]
	for (dx, dy) in dxy:
		(nx, ny) = (x + dx, y + dy)
		if not 0 <= nx < w:
			continue
		if not 0 <= ny < h:
			continue
		if dp[ny][nx] <= d + 1:
			continue
		dp[ny][nx] = d + 1
		q.append((nx, ny))
		ans = max(ans, d + 1)
print(ans)


(h, w) = map(int, input().split())
n = []
a = []
a.append(['&'] * (w + 2))
for i in range(h):
	arrc = list(input())
	arrc = ['&'] + arrc + ['&']
	b = arrc
	for j in range(len(arrc)):
		if b[j] == '#':
			n.append((i + 1, j))
	a.append(b)
a.append(['&'] * (w + 2))
p = [[1, 0], [0, 1], [-1, 0], [0, -1]]
cnt = -1
while n:
	cnt += 1
	n2 = []
	for (i, j) in n:
		for (di, dj) in p:
			di += i
			dj += j
			if a[di][dj] == '.':
				a[di][dj] = '#'
				n2.append((di, dj))
	n = n2
print(cnt)


(h, w) = map(int, input().split())
a = ['*' * (w + 2)] + ['*' + input() + '*' for _ in range(h)] + ['*' * (w + 2)]
from collections import deque
d = deque()
c = [[0] * w for _ in range(h)]
for i in range(1, h + 1):
	for j in range(1, w + 1):
		if a[i][j] == '#':
			d.append([i, j])
di = [[0, 1], [1, 0], [-1, 0], [0, -1]]
while d:
	g = d.popleft()
	for i in di:
		x = g[0] + i[0]
		y = g[1] + i[1]
		if a[x][y] == '.':
			if c[x - 1][y - 1] == 0:
				d.append([x, y])
				c[x - 1][y - 1] = c[g[0] - 1][g[1] - 1] + 1
m = 0
for i in range(h):
	for j in range(w):
		m = max(m, c[i][j])
print(m)


from collections import deque
(h, w) = map(int, input().split())
alist = [input().strip() for i in range(h)]
dxy = [(0, 1), (1, 0), (0, -1), (-1, 0)]
INF = 99999
dp = [[INF] * w for i in range(h)]
q = deque()
for (y, row) in enumerate(alist):
	for (x, c) in enumerate(row):
		if c == '#':
			dp[y][x] = 0
			q.append((x, y))
while q:
	(x, y) = q.popleft()
	d = dp[y][x]
	for (dx, dy) in dxy:
		(nx, ny) = (x + dx, y + dy)
		if not 0 <= nx < w:
			continue
		if not 0 <= ny < h:
			continue
		if dp[ny][nx] <= d + 1:
			continue
		dp[ny][nx] = d + 1
		q.append((nx, ny))
print(max((max(row) for row in dp)))


from collections import deque
(h, w) = map(int, input().split())
inf = 10 ** 6
a = [[0] * (w + 2)] + [[0] + [inf] * w + [0] for _ in range(h)] + [[0] * (w + 2)]
d = deque()
for i in range(h):
	for (j, k) in enumerate(input()):
		if k == '#':
			a[i + 1][j + 1] = 0
			d.append((i + 1, j + 1))
stp = ((0, 1), (0, -1), (1, 0), (-1, 0))
res = 0
while d:
	(x, y) = d.popleft()
	for (k, l) in stp:
		(nx, ny) = (x + k, y + l)
		if a[x][y] + 1 < a[nx][ny]:
			a[nx][ny] = a[x][y] + 1
			res = max(res, a[nx][ny])
			d.append((nx, ny))
print(res)