H, W = map(int, input().split())
S = [None] * H
for i in range(H):
    S[i] = input()


def dfs(h, w, gh, gw, visited, count):
    min_move = float("inf")
    reach_goal = False
    # up
    if (h >= 1) and (S[h - 1][w] != "#") and (not visited[h - 1][w]):
        if (h - 1, w) == (gh, gw):
            return count + 1
        visited[h - 1][w] = True
        ret = dfs(h - 1, w, gh, gw, visited, count + 1)
        visited[h - 1][w] = False
        if (ret != -1) and ret < min_move:
            min_move = ret
            reach_goal = True
    # down
    if (h < H - 1) and (S[h + 1][w] != "#") and (not visited[h + 1][w]):
        if (h + 1, w) == (gh, gw):
            return count + 1
        visited[h + 1][w] = True
        ret = dfs(h + 1, w, gh, gw, visited, count + 1)
        visited[h + 1][w] = False
        if (ret != 0) and ret < min_move:
            min_move = ret
            reach_goal = True
    # left
    if (w >= 1) and (S[h][w - 1] != "#") and (not visited[h][w - 1]):
        if (h, w - 1) == (gh, gw):
            return count + 1
        visited[h][w - 1] = True
        ret = dfs(h, w - 1, gh, gw, visited, count + 1)
        visited[h][w - 1] = False
        if (ret != 0) and (ret < min_move):
            min_move = ret
            reach_goal = True
    # right
    if (w < W - 1) and (S[h][w + 1] != "#") and (not visited[h][w + 1]):
        if (h, w + 1) == (gh, gw):
            return count + 1
        visited[h][w + 1] = True
        ret = dfs(h, w + 1, gh, gw, visited, count + 1)
        visited[h][w + 1] = False
        if (ret != 0) and (ret < min_move):
            min_move = ret
            reach_goal = True
    if reach_goal:
        return min_move
    else:
        return -1


visited = [[False for _ in range(W)] for _ in range(H)]
ans = 0
for gh in range(H):
    for gw in range(W):
        if S[gh][gw] == "#":
            continue
        for h in range(H):
            for w in range(W):
                if S[h][w] == "#":
                    continue
                if (h, w) == (gh, gw):
                    continue
                visited[h][w] = True
                min_move = dfs(h, w, gh, gw, visited, 0)
                visited[h][w] = False
                if min_move > ans:
                    ans = min_move

print(ans)
