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

def cost(x):
    v=[[0]*w for _ in range(h)]
    v[x[1]][x[0]]=1
    que = [x]
    ans=-1
    while que:
        newque = []
        for X,Y in que:
            for x,y in ((0,-1),(-1,0),(0,1),(1,0)):
                if 0<=X+x<w and 0<=Y+y<h and g[Y+y][X+x]=='.' and v[Y+y][X+x]==0:
                    v[Y+y][X+x] = 1
                    newque.append((X+x,Y+y))
        ans+=1
        que = newque
    return ans

ans = 0
for i in range(w):
    for j in range(h):
        if g[j][i]=='.':
            ans = max(ans,cost((i,j)))
print(ans)