import queue
H, W = list(map(int, input().split()))
M = [[i for i in input()] for j in range(H)]

def bfs(x, y):
  D = [[10 ** 9 for i in range(W)] for j in range(H)]
  q = queue.Queue()
  q.put([x, y])
  D[y][x] = 0
  direct = [[-1, 0], [1, 0], [0, -1], [0, 1]]
  max_distance = 0
  while q.qsize() != 0:
    x, y = q.get()
    for dx, dy in direct:
      nx, ny = x + dx, y + dy
      if nx < 0 or nx >= W or ny < 0 or ny >= H:
        continue
      if M[ny][nx] == "#":
        continue
      if D[ny][nx] > D[y][x] + 1:
        D[ny][nx] = D[y][x] + 1
        max_distance = max([max_distance, D[ny][nx]])
        q.put([nx, ny])
  return max_distance

result = 0
for y in range(H):
  for x in range(W):
    result = max([result, bfs(x, y)])
print(result)