def max_array(Array):
  _max = 0
  for i in range(len(Array)):
    if max(Array[i]) > _max:
      _max = max(Array[i])
  return _max
  
def check(i, j):
  exp = length[i][j] + 1
  if i > 0:
    if length[i-1][j] == -1 and S[i-1][j]:
      length[i-1][j] = exp
      check(i-1, j)
  if i < H-1:
    if length[i+1][j] == -1 and S[i+1][j]:
      length[i+1][j] = exp
      check(i+1, j)
  if j > 0:
    if length[i][j-1] == -1 and S[i][j-1]:
      length[i][j-1] = exp
      check(i, j-1)
  if j < W-1:
    if length[i][j+1] == -1 and S[i][j+1]:
      length[i][j+1] = exp
      check(i, j+1)

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

for i in range(H):
  A = input()
  for j in range(W):
    S[i].append(True if A[j] == '.' else False)
  
_max = 0
for i in range(H):
  for j in range(W):
    if S[i][j]:
      length = [[-1] * W for i in range(H)]
      length[i][j] = 0
      check(i, j)
      num = max_array(length)
      #print(num, length)
      
      if num > _max:
        _max = num

print(_max)