import numpy as np
import copy
H,W = list(map(int,input().split()))

Maze = []
for i in range(H):
    Maze.append(str(input().split()[0]))



def dfs(x,y,seen,ans):
    Map[y][x] = min(Map[y][x],ans)
    for c in [[1,0],[0,1],[-1,0],[0,-1]]:
        if 0<=x+c[0]<W and 0<=y+c[1]<H:
            if Maze[y+c[1]][x+c[0]] == '.'  and [x+c[0],y+c[1]] not in seen:
                seen.append([x+c[0],y+c[1]])
                dfs(x+c[0],y+c[1],seen,ans+1)
                seen.pop(-1)

maxL = []
MapSet = [[np.inf if Maze[j][i]=='.' else -np.inf for i in range(W)] for j in range(H)]
for i in range(W):
    for j in range(H):
        if Maze[j][i] == '.':
            Map = copy.deepcopy(MapSet)
            dfs(i,j,[i,j],0)
            maxL.append(np.array(Map).max())
print(int(max(maxL)))