def main():
    import sys
    import numpy as np
    H,W=list(map(int,sys.stdin.readline().split()))
    meiz=[]
    for i in range(H):
        S=sys.stdin.readline().strip()
        meiz.append([0 if s=='.' else 1 for s in S])

    #道→0 壁→1
    
    #meiz=np.array(meiz)
    
    #dp=[[0]*W for _ in range(H)]
    
    #FRTO=np.array(H,W,H,W)

    def dfs(x,y,tx,ty,d):
        if x==tx and y==ty:
            return 0

        if AL[y][x]:
            return 10**6

        AL[y][x]=1
        out=10**6
        if x!=0 and meiz[y][x-1]==0:
            t=dfs(x-1,y,tx,ty,d+1)
            out=t if t<out else out

        if x!=W-1 and meiz[y][x+1]==0 :
            t=dfs(x+1,y,tx,ty,d+1)
            out=t if t<out else out
        if y!=0 and meiz[y-1][x]==0:
            t=dfs(x,y-1,tx,ty,d+1)
            out=t if t<out else out
        if y!=H-1 and meiz[y+1][x]==0 :
            t=dfs(x,y+1,tx,ty,d+1)
            out=t if t<out else out
        
        return out+1

    mx=0
    for y in range(H):
        for x in range(W):
            for ty in range(H):
                for tx in range(W):
                    if meiz[y][x]==1:
                        continue
                    if meiz[ty][tx]==1:
                        continue
                    if y==ty and x==tx:
                        continue
                    if x not in [0,W-1] and meiz[y][x-1]==0 and meiz[y][x+1]==0:
                        continue
                    if y not in [0,H-1] and meiz[y-1][x]==0 and meiz[y+1][x]==0:
                        continue           
                    AL=[[0]*W for _ in range(H)]
                    t=dfs(x,y,tx,ty,0)
                    mx=t if t>mx else mx

    print(mx)

main()
