def main():
    from copy import deepcopy
    from collections import deque
    h, w = map(int, input().split())
    wall = ["#"] * (w + 2)
    maze = [wall]
    for _ in range(h):
        line = ["#"] + list(input()) + ["#"]
        maze.append(line)
    maze.append(wall)

    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            m = deepcopy(maze)
            que = deque()
            que.append((i, j, 0))
            tmp = 0
            while que:
                (x, y, c) = que.popleft()
                if m[x][y] == "#":
                    continue
                if m[x][y] == ".":
                    m[x][y] = "#"
                tmp = max(tmp, c)

                for v, w in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                    que.append((x + v, y + w, c + 1))

            ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()
