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 < 0 or new_y >= h or new_x < 0 or new_x >= w :
        continue
      if 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 = [input() for i in range(h)]

ans = 0
for i in range(0,h) :
  for j in range(0,w):
    for k in range(0,h) :
      for l in range(0,w) :
        sy = i ; sx = j
        gy = k ; gx = l
        if maze[sy][sx] == '#' or maze[gy][gx] == '#' :
          continue
        visited = [[-1]*w for _ in range(h)]
        temp = bfs(maze, visited, sy, sx, gy, gx)
        if ans < temp :
          ans = temp

print(ans)