
H, W = map(int, input().split())
edges = [[None for i in range(W)] for i in range(H)]

for i in range(H):
  s = list(map(str, input()))
  for j in range(W):
    edges[i][j] = s[j] 


def find_next(i, j):
  next = []
  if i > 0 and edges[i-1][j] == ".":
    next.append((i-1, j))
  if i < H - 1 and edges[i+1][j] == ".":
    next.append((i+1, j))
  if j > 0 and edges[i][j-1] == ".":
    next.append((i, j-1))
  if j < W - 1 and edges[i][j+1] == ".":
    next.append((i, j+1))
  return next

inf = 9999999999999999999

def dfs(i, j):
  colors = [[["white"] for i in range(W)] for j in range(H)]
  stack = [(i, j)]
  distance = [[inf for i in range(W)] for j in range(H)]
  distance[i][j] = 0

  while stack:
    i, j = map(int, stack.pop())
    colors[i][j] = "black"
    for (x, y) in find_next(i, j):
      if colors[x][y] != "black":
        distance[x][y] = min(distance[i][j] + 1, distance[x][y])
        stack.append((x, y))
  
  return distance


import itertools
ans = -1
for i in range(H):
  for j in range(W):
    L = list(itertools.chain.from_iterable(dfs(i, j)))
    m = max(list(filter(lambda x: x != inf, L)))
    ans = max(ans, m)

print(ans)