import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from copy import deepcopy



h, w = list(map(int, readline().split()))

s = [eval(input()) for i in range(h)]

q = []

start = []

dist = [[False] * w for _ in range(h)]

for i in range(h):

    for j in range(w):

        if s[i][j] != '#':

            start.append((i, j))

        else:

            dist[i][j] = True

test = [(0, 1), (0, -1), (1, 0), (-1, 0)]

ans = []

while start:

    check = deepcopy(dist)

    q = [start.pop()]

    check[list(q)[0][0]][list(q)[0][1]] = True

    cnt = -1

    while q:

        cnt += 1

        qq = []

        memo = len(q)

        memo_cnt = 0

        for y, x in q:

            for dy, dx in test:

                yy, xx = y + dy, x + dx

                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:

                    memo_cnt += 1

                    continue

                else:

                    check[yy][xx] = True

                    qq.append((yy, xx))

        q = qq

    ans.append(cnt)

else:

    print((max(ans)))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from copy import deepcopy



h, w = list(map(int, readline().split()))

s = [eval(input()) for i in range(h)]

q = []

start = []

dist = [[False] * w for _ in range(h)]

for i in range(h):

    for j in range(w):

        if s[i][j] != '#':

            start.append([i, j])

        else:

            dist[i][j] = True

test = [(0, 1), (0, -1), (1, 0), (-1, 0)]

ans = 0

while start:

    check = deepcopy(dist)

    q = [start.pop()]

    check[q[0][0]][q[0][1]] = True

    q[0] = tuple(q[0])

    cnt = -1

    while q:

        cnt += 1

        qq = []

        for y, x in q:

            for dy, dx in test:

                yy, xx = y + dy, x + dx

                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:

                    continue

                else:

                    check[yy][xx] = True

                    qq.append((yy, xx))

        q = qq

    ans = max(ans, cnt)

else:

    print(ans)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from copy import deepcopy

h, w = list(map(int, readline().split()))
s = [eval(input()) for i in range(h)]
q = []
start = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != "#":
            start.append((i, j))
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = []
while start:
    check = deepcopy(dist)
    q = [start.pop()]
    check[list(q)[0][0]][list(q)[0][1]] = True
    cnt = -1
    while q:
        cnt += 1
        qq = []
        memo = len(q)
        memo_cnt = 0
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    memo_cnt += 1
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans.append(cnt)
else:
    print((max(ans)))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from copy import deepcopy

h, w = list(map(int, readline().split()))
s = [eval(input()) for i in range(h)]
q = []
start = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != "#":
            start.append([i, j])
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = 0
while start:
    check = deepcopy(dist)
    q = [start.pop()]
    check[q[0][0]][q[0][1]] = True
    q[0] = tuple(q[0])
    cnt = -1
    while q:
        cnt += 1
        qq = []
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans = max(ans, cnt)
else:
    print(ans)

-            start.append((i, j)) +            start.append([i, j]) -ans = [] +ans = 0 -    check[list(q)[0][0]][list(q)[0][1]] = True +    check[q[0][0]][q[0][1]] = True +    q[0] = tuple(q[0]) -        memo = len(q) -        memo_cnt = 0 -                    memo_cnt += 1 -    ans.append(cnt) +    ans = max(ans, cnt) -    print((max(ans))) +    print(ans)