from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
  queue = deque([[sy, sx]])
  visited[sy][sx] = 0
  while queue:
    y, x = queue.popleft()
    if [y, x] == [gy, gx]:
      return visited[y][x]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_y, new_x = y+j, x+k
      if new_y >= H or new_y < 0 or new_x >= W or new_x < 0:
        continue
      elif maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
        visited[new_y][new_x] = visited[y][x] + 1
        queue.append([new_y, new_x])

H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
ans = 0
for sy in range(H):
  for sx in range(W):
    for gy in range(H):
      for gx in range(W):
        visited = [[-1]*W for j in range(H)]
        res = bfs(maze, visited, sy, sx, gy, gx)
        if res != None:
          ans = max(ans, res)
print(ans)