import copy
def dfs(x,y,z,grid,H,W):
    if(x-1>=0):
        if(grid[y][x-1]>z or grid[y][x-1]==0):
            grid[y][x-1]=z+1
            dfs(x-1,y,z+1,grid,H,W)
    if(x+1<W):
        if(grid[y][x+1]>z or grid[y][x+1]==0):
            grid[y][x+1]=z+1
            dfs(x+1,y,z+1,grid,H,W)
    if(y-1>=0):
        if(grid[y-1][x]>z or grid[y-1][x]==0):
            grid[y-1][x]=z+1
            dfs(x,y-1,z+1,grid,H,W)
    if(y+1<H):
        if(grid[y+1][x]>z or grid[y+1][x]==0):
            grid[y+1][x]=z+1
            dfs(x,y+1,z+1,grid,H,W)
    return 0


H,W=map(int,input().split())
grid=[]
tmp=[]
for i in range(H):
    S=str(input())
    tmp=[]
    for j in range(W):
        if(S[j]=="."):
            tmp.append(0)
        else:
            tmp.append(-1)
    grid.append(tmp)
ans=0
result=0
for i in range(W):
    for j in range(H):
        if(grid[j][i]==0):
            if(j-1>=0 and j+1<H and i-1>=0 and i+1<W):
                if(grid[j-1][i]+grid[j+1][i]+grid[j][i-1]+grod[i+1]<(-1)):
                        dataset=copy.deepcopy(grid)
                        dfs(i,j,1,dataset,H,W)
                        ans=max(dataset)
                        ans=max(ans)
                        result=max(result,ans)
            else:
                dataset=copy.deepcopy(grid)
                dfs(i,j,1,dataset,H,W)
                ans=max(dataset)
                ans=max(ans)
                result=max(result,ans)
print(result-1)