h, w = map(int, input().split())
maze = []

for i in range(h):
    maze.append(list(input()))


def bfs(start: list):
    global h, w, maze
    length = [[-1 for _ in range(w)] for _ in range(h)]
    check = [[False for _ in range(w)] for _ in range(h)]
    queue = [start]
    depth = 0
    res = -1
    while len(queue) > 0:
        [x, y, bx, by] = queue.pop(0)
        check[x][y] = True
        length[x][y] = length[bx][by] + 1
        res = max(res, length[x][y])

        depth += 1
        target = []
        if x != 0:
            target.append((x - 1, y))
        if x != h - 1:
            target.append((x + 1, y))
        if y != 0:
            target.append((x, y - 1))
        if y != w - 1:
            target.append((x, y + 1))

        for t in target:
            if not check[t[0]][t[1]]:
                if maze[t[0]][t[1]] == ".":
                    queue.append([t[0], t[1], x, y])

    return res


ans = -1

for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            ans = max(ans, bfs([i, j, i, j]))

print(ans)
