import copy
from collections import deque

h, w = map(int,input().split())

input_maze=[]
for i in range(h):
	input_maze.append(list(input()))

maze=[[-1 for j in range(w+2)] for i in range(h+2)]

#banpei
for i in range(h):
    for j in range(w):
        if input_maze[i][j]=='.':
            maze[i+1][j+1]=0
        else:
            maze[i+1][j+1]=-1

#print(maze)

max_route=0
direction=[[1,0],[-1,0],[0,1],[0,-1]]
for i in range(h):
    for j in range(w):
        copy_maze=copy.deepcopy(maze)
        start=[i+1,j+1]
        que=deque([])
        if maze[start[0]][start[1]]==0:
            copy_maze[start[0]][start[1]]=-1
            for d in direction:
                if copy_maze[start[0]+d[0]][start[1]+d[1]]==0:
                    que.append([start[0]+d[0],start[1]+d[1]])
                    copy_maze[start[0]+d[0]][start[1]+d[1]]=1
            while len(que)>0:
                tmp=que.popleft()
                for d in direction:
                    if copy_maze[tmp[0]+d[0]][tmp[1]+d[1]]==0:
                        que.append([tmp[0]+d[0],tmp[1]+d[1]])
                        copy_maze[tmp[0]+d[0]][tmp[1]+d[1]]=copy_maze[tmp[0]][tmp[1]]+1
                        if max_route<copy_maze[tmp[0]+d[0]][tmp[1]+d[1]]:
                            max_route=copy_maze[tmp[0]+d[0]][tmp[1]+d[1]]

                
print(max_route)