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

dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]
mx = 0 
for i in range(H//2 + 1): 
        for j in range(W):
                if S[i][j] == ".":
                        q = queue.Queue()
                        q.put([i, j, 0]) 
                        checked = [[0 for l in range(W)] for k in range(H)]
                        while not q.empty():
                                di = q.get()    
                                if mx < di[2]:
                                        mx = di[2]
                                checked[di[0]][di[1]] = -1
                                for k in range(4):
                                        nh = di[0] + dy[k]
                                        nx = di[1] + dx[k]
                                        if 0 <= nx < W and 0 <= nh < H and checked[nh][nx] == 0:
                                                if S[nh][nx] == ".":
                                                        q.put([nh, nx, di[2] + 1]) 
print(mx)