H, W = map(int, input().split())

S = list()
for i in range(H):
  S.append(list(map(lambda x: int(x == '.'), input())))

for i in range(H):
  S[i].append(0)
  S[i].append(0)
S.append([0 for _ in range(W + 2)])


def wfs(loc):
  moved = [
    [
      False for w in range(W + 2)
    ]
    for h in range(H + 2)
  ]
  queue = [(loc, 0)]
  ans = 0
  moved[loc[0]][loc[1]] = True
  while (queue):
    (h, w), move = queue.pop(0)
    for i, j in zip((1, -1, 0, 0), (0, 0, -1, 1)):
      _h, _w = h + i, w + j
      if not moved[_h][_w] and S[_h][_w] == 1:
        moved[_h][_w] = True
        queue.append(((_h, _w), move + 1))
    ans = max(ans, move)
  return ans

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, wfs((i, j)))
print(ans)
