from collections import deque


def BFS(x,y):
    color=[["white" for _ in range(w)] for _ in range(h)]
    D=[[0 for _ in range(w)] for _ in range(h)]

    color[x][y]="gray"
    D[x][y]=0
    queue=deque([[x,y]])

    num=0
    while len(queue)>0:
        a,b=queue.popleft()
        for c,d in [[1,0],[-1,0],[0,1],[0,-1]]:
            X,Y=a+c,b+d
            if 0<=X<h and 0<=Y<w:
                if color[X][Y]=="white" and S[X][Y]==".":
                    D[X][Y]=D[a][b]+1
                    num=max(num,D[X][Y])
                    color[X][Y]="gray"
                    queue.append([X,Y])
        color[X][Y]="black"

    return num


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]

ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]==".":ans=max(ans,BFS(i,j))
        
print(ans)