H, W = map(int, input().split())
S = []
for _ in range(H):
  S.append(list(input()))

N = H * W
D = []
for i in range(N):
  d = [N  for _ in range(N)]
  d[i] = 0
  D.append(d)
for row in range(H):
  for col in range(W):
    i = row * W + col
    if row < H - 1:
      j = i + H
      if S[row][col] == '.' and S[row+1][col] == '.':
        D[i][j] = D[j][i] = 1
    if col < W - 1:
      k = i + 1
      if S[row][col] == '.' and S[row][col+1] == '.':
        D[i][k] = D[k][i] = 1

for i in range(N):
  for j in range(N):
    for k in range(N):
      D[j][k] = min(D[j][k], D[j][i] + D[i][k])

print(max([max([e for e in d if e < N]) for d in D]))
