from collections import deque
H, W = map(int, input().split())

maze = [['#']*(W+2)]
for i in range(H):
    maze.append(list('#'+input()+'#'))
maze.append(['#']*(W+2))
ans = 0

for ii in range(1,H+1):
    for jj in range(1,W+1):
        if maze[ii][jj]=='#':continue
        temp = deque()
        temp.append([ii,jj])
        mazenum = [[0]*(W+2) for _ in range(H+2)]
        mazenum[ii][jj] = 0
        visited = [[False]*(W+2) for _ in range(H+2)]
        visited[ii][jj] = True

        while temp:
            p = temp.popleft()
            m = mazenum[p[0]][p[1]]
            for i, j in [[p[0]-1,p[1]], [p[0]+1, p[1]], [p[0],p[1]-1],[p[0],p[1]+1]]:
                if maze[i][j]=='.':
                    if not visited[i][j]:
                        temp.append([i, j])
                        mazenum[i][j] = m + 1
                        visited[i][j]= True        
        ans = max(ans, max(max(mazenum)))

print(ans)
