from collections import deque

H, W = map(int, input().split())
Maze = [["#"]*(W+2)]+[["#"]+list(input())+["#"] for _ in range(H)] + [["#"]*(W+2)]
Ans = 0
sy = 1
while sy <= H:
  sx = 1
  while sx <= W:
    if Maze[sy][sx] == ".":
        memo = [[False]*(W+2) for _ in range(H+2)]
        q = deque()
        q.append([[sy,sx],0])
        ans = 0
        while q:
          cur, cnt = q.popleft()
          Ans = max(ans, cnt)
          memo[cur[0]][cur[1]] = True
          for y, x in zip((0,0,1,-1),(1,-1,0,0)):
            if Maze[cur[0]+y][cur[1]+x] == "." and not memo[cur[0]+y][cur[1]+x]:
              q.append([[cur[0]+y,cur[1]+x],cnt+1])
    sx += 1
  sy += 1
print(Ans)