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 = [[-1]*(W) for _ in range((H))]
      memo[sy][sx] = 0
      q.append([sy, sx])
      while q:
        cy, cx = q.popleft()
        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 memo[ny][nx] < 0:
            q.append([ny, nx])
            memo[ny][nx] = memo[cy][cx] + 1
      ans = max(ans, max([max(m)  for m in memo]))
    sx += 1
  sy += 1
print(ans)