from collections import deque

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

def find_shortest():
  d = [[float("inf")] * w for i in range(h)]
  dx = [1, 0, -1, 0]
  dy = [0, 1, 0, -1]

  que = deque([])
  que.append((sy,sx))
  d[sy][sx] = 0

  while que:
    p = que.popleft()
    if p[0] == gy and p[1] == gx:
      break
    for i in range(4):
      nx = p[0] + dx[i]
      ny = p[1] + dy[i]
      if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
        que.append((nx, ny))
        d[nx][ny] = d[p[0]][p[1]] + 1
  return d[gy][gx]

route = []

sg = []
for j in range(h):
  for i in range(w):
    if maze[j][i] == '.':
      sg.append([j,i])

for sy,sx in sg:
  for gy,gx in sg:
    if find_shortest() != float("inf"):
      route.append(find_shortest())

ans = max(route)
print(ans)