def warshall_floyd(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

h, w = map(int, input().split())
square = []

for i in range(h):
  _s = input()
  for j in range(w):
    if _s[j] == ".":
      square.append((i, j))

squares = len(square)
d = [[float("inf") for i in range(squares)] for j in range(squares)]

for i in range(squares):
  d[i][i] = 0

for i in range(squares - 1):
  for j in range(i + 1, squares):
    a_x, a_y = square[i]
    b_x, b_y = square[j]
    if (a_x == b_x and abs(a_y - b_y) == 1) or (a_y == b_y and abs(a_x - b_x) == 1):
      d[i][j] = d[j][i] = 1

d = warshall_floyd(d, squares)
print(max(max(d)))