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

array = []
for _ in range(H):
  array.append(input())
  
max_path = 0
import queue
from collections import deque

for h in range(H):
  for w in range(W):    
    if array[h][w] == ".":
#      que = queue.Queue()
      que = deque()
      checked = [[-1 if array[h][w] =="." else -2 for w in range(W)] for h in range(H)]
#      que.put((w, h, 0))
      que.append((w, h, 0))
#      while not que.empty():
#        x, y, l = que.get()
      while len(que) > 0:
        x, y, l = que.pop()
        checked[y][x] = l
        max_path = max(max_path, l)
        if (x > 0) and (checked[y][x-1] == -1):
#          que.put((x-1, y, l+1))
           que.append((x-1, y, l+1))
        if (y > 0) and (checked[y-1][x] == -1):
          que.append((x, y - 1, l+1))
        if (x < W - 1) and (checked[y][x+1] == -1):
          que.append((x + 1, y, l+1))
        if (y < H - 1) and (checked[y+1][x] == -1):
          que.append((x, y + 1, l+1))
        
          
        
  
print(max_path)
