output_description: Print the maximum possible number of moves Aoki has to make.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W
      S_{11}...S_{1W}
      :
      S_{H1}...S_{HW}
attempt: import sys, copy
  
  sys.setrecursionlimit(10**6)
  int1 = lambda x: int(x) - 1
  p2D = lambda x: print(*x, sep="\n")
  
  
  def IS():
      return sys.stdin.readline()
  
  
  def II():
      return int(sys.stdin.readline())
  
  
  def MI():
      return map(int, sys.stdin.readline().split())
  
  
  def LI():
      return list(map(int, sys.stdin.readline().split()))
  
  
  def LI1():
      return list(map(int1, sys.stdin.readline().split()))
  
  
  def LII(rows_number):
      return [II() for _ in range(rows_number)]
  
  
  def LLI(rows_number):
      return [LI() for _ in range(rows_number)]
  
  
  def LLI1(rows_number):
      return [LI1() for _ in range(rows_number)]
  
  
  def main():
      H, W = MI()
      maze = [[-1 for _ in range(W)] for _ in range(H)]
      for i in range(H):
          S = IS()
          for j, s in enumerate(S):
              if s == "#":
                  maze[i][j] = "#"
  
      def bfs(sx, sy):
          from collections import deque
  
          que = deque()
          dist_map = copy.deepcopy(maze)
          dist_map[sy][sx] = 0
          que.append((sx, sy))
          res = 0
          while len(que) > 0:
              x, y = que.popleft()
              for dx, dy in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
                  nx = x + dx
                  ny = y + dy
                  if 0 <= nx < W and 0 <= ny < H:
                      if dist_map[ny][nx] == -1:
                          dist_map[ny][nx] = dist_map[y][x] + 1
                          res = max(res, dist_map[ny][nx])
                          que.append((nx, ny))
          return res
  
      ans = -1
      for i in range(H):
          for j in range(W):
              if maze[i][j] == -1:
                  dist = bfs(j, i)
                  if dist > ans:
                      ans = dist
      print(ans)
  
  
  main()
  
problem_description: Statement
  
  Takahashi has a maze, which is a grid of H \times W squares with H horizontal
  rows and W vertical columns.
  
  The square at the i-th row from the top and the j-th column is a "wall" square
  if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.
  
  From a road square, you can move to a horizontally or vertically adjacent road
  square.
  
  You cannot move out of the maze, move to a wall square, or move diagonally.
  
  Takahashi will choose a starting square and a goal square, which can be any
  road squares, and give the maze to Aoki.
  
  Aoki will then travel from the starting square to the goal square, in the
  minimum number of moves required.
  
  In this situation, find the maximum possible number of moves Aoki has to make.
samples: [{"input": "3 3\n    ...\n    ...\n    ...", "output": "4\n    \n\nIf Takahashi chooses the top-left square as the starting square and the\nbottom-right square as the goal square, Aoki has to make four moves.\n\n* * *"}, {"input": "3 5\n    ...#.\n    .#.#.\n    .#...", "output": "10\n    \n\nIf Takahashi chooses the bottom-left square as the starting square and the\ntop-right square as the goal square, Aoki has to make ten moves."}]