def make_noreplace_comb(list):
    res=[]
    for i in range(len(list)-1):
        for j in range(i+1,len(list)):
            res.append([list[i],list[j]])
    return res

def Maze_Breadth(Maze,start_goal):

    h=len(Maze)
    w=len(Maze[0])
    #ここに距離も格納
    footprints=[[-1 for i in range(w)] for j in range(h)]

    que=[start_goal[0]]

    distance=0
    while True:
        Que=[]

        for pos in que:
            
            footprints[pos[0]][pos[1]]=distance

            if pos[0]==start_goal[1][0] and pos[1]==start_goal[1][1]:
                
                break

            if not pos[0]==0:
                if Maze[pos[0]-1][pos[1]]=="." and footprints[pos[0]-1][pos[1]]==-1:
                    Que.append([pos[0]-1,pos[1]])
            
            if not pos[0]==h-1:
                if Maze[pos[0]+1][pos[1]]=="." and footprints[pos[0]+1][pos[1]]==-1:
                    Que.append([pos[0]+1,pos[1]])

            if not pos[1]==0:
                if Maze[pos[0]][pos[1]-1]=="." and footprints[pos[0]][pos[1]-1]==-1:
                    Que.append([pos[0],pos[1]-1])
            
            if not pos[1]==w-1:
                if Maze[pos[0]][pos[1]+1]=="." and footprints[pos[0]][pos[1]+1]==-1:
                    Que.append([pos[0],pos[1]+1])
        que=Que
        distance+=1

        if len(Que)==0:
            break
    return footprints[start_goal[1][0]][start_goal[1][1]]

N,M=input().split(" ")

N=int(N)
M=int(M)

H,W=N,M

Ss=[]

for i in range(H):
    S=input()
    Ss.append([S[i] for i in range(len(S))])

road_coords=[]

for i in range(H):
    for j in range(W):
        if Ss[i][j]==".":
            road_coords.append([i,j])

patterns=make_noreplace_comb(road_coords)

ans=0
max_pattern=None
for s_g in patterns:
    temp=Maze_Breadth(Ss,s_g)
    if temp>ans:
        ans=temp
        max_pattern=s_g

print(ans)
