# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    walls = [[c == '#' for c in s] for s in args[1:]]

    head = None
    for y in range(h):
        for x in range(w):
            if not walls[y][x]:
                head = (x, y)
                break
        if head:
            break

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

    count = 0
    tail = head

    Q = deque([head+(0,)])

    while Q:
        x, y, c = Q.popleft()
        if walls[y][x] or passed[y][x]:
            continue

        passed[y][x] = True
        if count < c:
            tail = (x, y)

        if 0 < x:
            Q.append((x-1, y, c+1))
        if x+1 < w:
            Q.append((x+1, y, c+1))
        if 0 < y:
            Q.append((x, y-1, c+1))
        if y+1 < h:
            Q.append((x, y+1, c+1))

    Q.append(tail+(0,))
    passed = [[False]*w for _ in range(h)]

    count = 0

    while Q:
        x, y, c = Q.popleft()
        if walls[y][x] or passed[y][x]:
            continue

        passed[y][x] = True
        count = max(c, count)

        if 0 < x:
            Q.append((x-1, y, c+1))
        if x+1 < w:
            Q.append((x+1, y, c+1))
        if 0 < y:
            Q.append((x, y-1, c+1))
        if y+1 < h:
            Q.append((x, y+1, c+1))

    return str(count)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
