from collections import deque
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]

dxy = [[-1, 0], [0, 1], [1, 0], [0, -1]]

ans = 0
for h in range(H):
  for w in range(W):
    if maze[h][w] == '#':
      continue
    d_maze = [[-1]*W for _ in range(H)]
    d_maze[h][w] = 0
    p = [[h, w]]
    p = deque(p)
    while p:
      rh, rw =  p.popleft()
      for i, j in dxy:
        if rh + i < 0 or rh + i >= H:
          continue
        if rw + j < 0 or rw + j >= W:
          continue
        if d_maze[rh + i][rw + j] == -1 and not maze[rh + i][rw + j] == '#':
          d_maze[rh + i][rw + j] = d_maze[rh][rw] + 1
          p.append([rh + i, rw + j])
    ans = max(ans, max(max([l for l in d_maze])))
print(ans)