import queue
H, W = map(int, input().split())
S= [input() for i in range(H)]

ans=-1

def dfs(start,goal):
    distance=[[-1]*H for j in range(W)]
    li_x=[1,-1,0,0]
    li_y=[0,0,1,-1]
    q = queue.Queue()
    q.put(start)
    distance[start[0]][start[1]]=0

    while not q.empty():
        hoge=q.get()
        x=hoge[0]
        y=hoge[1]
        dis=distance[x][y]

        for i in range(4):
            x1=x+li_x[i]
            y1=y+li_y[i]
            if (0 <=x1 < W and 0 <= y1 < H):
                if distance[x1][y1] == -1:
                    if S[y1][x1]=='.':
                        q.put([x1,y1])
                        distance[x1][y1]=dis+1

    return distance[goal[0]][goal[1]]

done=[]
for sx in range(W):
    for gx in range(W):
        for sy in range(H):
            for gy in range(H):
                if S[sy][sx]=='.' and S[gy][gx]=='.':
                    if [gx,gy,sx,sy] not in done:
                        re=dfs([sx,sy],[gx,gy])
                        done.append([sx,sy,gx,gy])
                        if re > ans:
                            ans=re

print(ans)
