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:
        nh = rh + i
        nw = rw + j
        if 0 <= nh < H and 0 <= nw < W and maze[nh][nw] == '.' and d_maze[nh][nw] == -1:
          d_maze[nh][nw] = d_maze[rh][rw] + 1
          p.append([nh, nw])
    ans = max(ans, max(max([l for l in d_maze])))
print(ans)