from collections import deque
def bfs(S,H,W,sh,sw):
    dist=[[-1]*W for i in range(H)]
    dist[sh][sw]=0

    d=deque()
    d.append([sh,sw])
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    lo=0
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        d.popleft()
        for dir in range(4):
            nh=h+dx[dir]
            nw=w+dy[dir]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(dist[nh][nw]!=-1 or S[nh][nw]=='#'):
                continue
            dist[nh][nw]=dist[h][w]+1
            lo=dist[nh][nw]
            S[nh][nw]=='#'
            d.append([nh,nw])
    return lo

H,W=map(int,input().split())
S=[input() for i in range(H)]
ans=-1
for i in range(H):
    for j in range(W):
        ans=max(ans,bfs(S,H,W,i,j))
print(ans)