from collections import deque

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