import copy, collections, itertools
H, W = [int(_) for _ in input().split()]
S = [['#'] * (W + 2)] + [['#'] + list(input()) + ['#']
                          for _ in range(H)] + [['#'] * (W + 2)]
ans = 0
def bfs(x, y, S):
    s = copy.deepcopy(S)
    q = collections.deque([(x, y, 0)])
    while q:
        x, y, d = q.popleft()
        s[x][y] = '#'
        for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            nx, ny = x + dx, y + dy
            if s[nx][ny] == '.':
                q += [[nx, ny, d + 1]]
    return x, y, d
for x,y in itertools.product(range(1, H + 1), range(1, W + 1)):
    if S[x][y] == '.':
        break
x, y, d = bfs(x, y, S)
x, y, d = bfs(x, y, S)
print(d)
