r,c=map(int,input().split())
meiro=[list(input()) for i in range(r)]
#迷路の白マスを数える作業
white=[]
for i in range(r):
    for j in range(c):
        if meiro[i][j]==".":
            white.append([i+1,j+1])
#迷路の外を＃で囲む
for i in range(r):
    meiro[i].insert(c,"#")
    meiro[i].insert(0,"#")
meiro.insert(0,["#"]*(c+2))
meiro.append(["#"]*(c+2))
#print(meiro)
def bfs(sx,sy):
    idou=[[0,1],[0,-1],[1,0],[-1,0]]
    tesuu=[[-1]*(c+2) for i in range(r+2)]
    from collections import deque
    tesuu[sx][sy]=0
    #print(tesuu)
    quest=deque([[sx,sy]])#最初に見る場所
    while len(quest)!=0:
        see=quest.popleft()
        for i in idou:
            if meiro[see[0]+i[0]][see[1]+i[1]]=="#":
                continue
            if tesuu[see[0]+i[0]][see[1]+i[1]]!=-1:
                continue
            quest.append([see[0]+i[0],see[1]+i[1]])
            tesuu[see[0]+i[0]][see[1]+i[1]]=tesuu[see[0]][see[1]]+1
    return max(max(tesuu))
tesuu_=[]
for i in range(len(white)):
    tesuu_.append(bfs(white[i][0],white[i][1]))
print(max(tesuu_))