### BUGGY CODE ###

import numpy as np


def check(y, x, p):
    l = x - p
    r = x + p
    t = y - p
    b = y + p
    if b < T:
        if a[b, 0 if l < 0 else l: r + 1 if r < T else T].any():
            return True
    if t >= 0:
        if a[t, 0 if l < 0 else l: r + 1 if r < T else T].any():
            return True
    if r < T:
        if a[0 if t < 0 else t: b + 1 if b < T else T, r].any():
            return True
    if l >= 0:
        if a[0 if t < 0 else t: b + 1 if b < T else T, l].any():
            return True
    return False


H, W = map(int, input().split())
T = H + W
a = np.zeros((T, T), dtype=int)
ans = np.zeros((H, W), dtype=int)
for h in range(H):
    s = input()
    for w in range(W):
        if s[w] == '#':
            a[h + w, W + h - w - 1] = 1

for h in range(H):
    if h == 0:
        for w in range(W):
            if w == 0:
                for i in range(H + W):
                    if check(0, W - 1, i):
                        ans[0, 0] = i
                        break
            else:
                p = ans[0, w - 1]
                if p > 0 and check(h + w, W + h - w - 1, p - 1):
                        ans[h, w] = p - 1
                elif check(h + w, W + h - w - 1, p):
                    ans[h, w] = p
                else:
                    ans[h, w] = p + 1

    else:
        for w in range(W):
            if w == 0:
                p = ans[h - 1, 0]
                if p > 0 and check(h + w, W + h - w -1, p - 1):
                        ans[h, w] = p - 1
                elif check(h + w, W + h - w - 1, p):
                    ans[h, w] = p
                else:
                    ans[h, w] = p + 1
            else:
                p1 = ans[h, w - 1]
                p2 = ans[h - 1, w]
                pmax = max(p1, p2)
                pmin = min(p1, p2)
                if pmax - pmin == 2:
                    ans[h, w] = (pmax + pmin) // 2
                elif pmax - pmin == 1:
                    if check(h + w, W + h - w - 1, pmin):
                        ans[h, w] = pmin
                    else:
                        ans[h, w] = pmax
                else:
                    if p1 > 0 and check(h + w, W + h - w - 1, p1 - 1):
                        ans[h, w] = p1 - 1
                    elif check(h + w, W + h - w - 1, p1):
                        ans[h, w] = p1
                    else:
                        ans[h, w] = p1 + 1

print(ans.max())

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
a = [[0] * W for _ in range(H)]
q = deque([])
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            a[i][j] = 1
            q.appendleft((i, j, 0))

while True:
    try:
        i, j, val = q.pop()
        if i > 0 and a[i - 1][j] == 0:
            q.appendleft((i - 1, j, val + 1))
            a[i - 1][j] = 1
        if i < H - 1 and a[i + 1][j] == 0:
            q.appendleft((i + 1, j, val + 1))
            a[i + 1][j] = 1
        if j > 0 and a[i][j - 1] == 0:
            q.appendleft((i, j - 1, val + 1))
            a[i][j - 1] = 1
        if j < W - 1 and a[i][j + 1] == 0:
            q.appendleft((i, j + 1, val + 1))
            a[i][j + 1] = 1
    except:
        print(val)
        break