import copy
H,W=map(int,input().split())

def BFS(h,w,maze):


maze=[]
maze.append("#"*W)
for h in range(H):
    maze_e=input()
    line=[]

    maze.append("#"+line+"#")

maze.append("#"*W)


maze_ori=copy.deepcopy(maze)

maxd=0

for h in range(1,H+1):
    for w in range(1,W+1):
        maze=copy.deepcopy(maze_ori)
        if maze[h][w]="#":
            continue
        else:
            next_flag=True


        direction=[[-1,0],[0][-1],[1,0],[0][1]])
        distance=0
        maze[h][w]=distance

        next_list=[h,w]
        while next_flag is True:
            p_list=next_list[]
            next_list=[]
            distance+=1
            next_flag=False
            for p in p_list:
                for d in direction:
                    i=p[0]+d[0]
                    j=p[1]+d[1]

                    if maze[i,j]==".":
                        maze[i,j]=distance
                        next_list.append([i,j])
                        next_flag=True
            
        maxd=max(maxd,distance-1)

print(maxd)