h, w = map(int, input().split())
maze = [input() for i in range(h)]

def mapping(m, n):
  
  if not(0 <= m < h) or not(0 <= n < w):
    return
  if (maze[m][n] == "#") or judge[m][n]:
    return
  
  if (0 <= m+1 < h):
    if not(maze[m+1][n] == "#"):
      MAP[m+1][n] = min(abs(MAP[m+1][n]), MAP[m][n]+1)
  if (0 <= m-1 < h):
    if not(maze[m-1][n] == "#"):
      MAP[m-1][n] = min(abs(MAP[m-1][n]), MAP[m][n]+1)
  if (0 <= n+1 < w):
    if not(maze[m][n+1] == "#"):
      MAP[m][n+1] = min(abs(MAP[m][n+1]), MAP[m][n]+1)
  if (0 <= n-1 < w):
    if not(maze[m][n-1] == "#"):
      MAP[m][n-1] = min(abs(MAP[m][n-1]), MAP[m][n]+1)
      
  judge[m][n] = True
  
  mapping(m+1, n)
  mapping(m-1, n)
  mapping(m, n+1)
  mapping(m, n-1)
      
ans = 0

for i in range(h):
  for j in range(w):
    if maze[i][j] == ".":
      MAP = [[-float('inf')]*w for i in range(h)]
      judge = [[False]*w for i in range(h)]
      MAP[i][j] = 0
      can = 0
      mapping(i, j)
      for k in range(h):
        for l in range(w):
          can = max(can, MAP[k][l])
      ans = max(ans, can)

print(ans)