import sys
import copy

h, w = map(int, input().split())
S = [input() for _ in range(h)]


def get_shortest_steps(S, visited, i, j, l, m, steps):
    if i == l and j == m:
        return steps
    if i == -1 or i == h or j == -1 or j == w:
        return sys.maxsize
    if visited[i * 20 + j]:
        return sys.maxsize
    if S[i][j] == "#":
        return sys.maxsize
    visited[i * 20 + j] = True
    returned_steps1 = get_shortest_steps(S, copy.copy(visited), i + 1, j, l, m, steps + 1)
    returned_steps2 = get_shortest_steps(S, copy.copy(visited), i, j + 1, l, m, steps + 1)
    returned_steps3 = get_shortest_steps(S, copy.copy(visited), i - 1, j, l, m, steps + 1)
    returned_steps4 = get_shortest_steps(S, copy.copy(visited), i, j - 1, l, m, steps + 1)
    # print(returned_steps1, returned_steps2, returned_steps3, returned_steps4)
    return min(returned_steps1, returned_steps2, returned_steps3, returned_steps4)


result = -1
for i in range(h):
    for j in range(w):
        for l in range(h):
            for m in range(w):
                visited = [False] * (h * 20 + w + 1)
                shortest_steps = get_shortest_steps(S, visited, i, j, l, m, 0)
                if shortest_steps == sys.maxsize:
                    continue
                if shortest_steps > result:
                    result = shortest_steps
print(result)
