# D - Maze Master
from collections import deque


def bfs(start: int):
    queue = deque([start])
    dist = {start: 0}
    while queue:
        x = queue.popleft()
        for nx in (x + 1, x - 1, x + W, x - W):
            if maze[nx] and nx not in dist:
                dist[nx] = dist[x] + 1
                queue.append(nx)
    return max(dist.values())


def main():
    global H, W, maze
    H, W, *S = open(0).read().split()
    H, W = int(H) + 2, int(W) + 2
    maze = [0] * W  # flatten S and put sentinels
    for s in S:
        maze += [0] + [c == "." for c in s] + [0]
    maze += [0] * W
    ans = max(bfs(i) for i, x in enumerate(maze) if x)
    print(ans)


if __name__ == "__main__":
    main()
