H, W = [int(i) for i in input().split()]
SSS = [["#" for i in range(W+2)]]
for i in range(H):
    buff = "#"+input()+"#"
    SSS.append([i for i in buff])
SSS.append(["#" for i in range(W+2)])

def maxlen(a,b):
    willgo = [[a,b]]
    finish =[]
    dist = [[-1 for i in range(W+2)] for j in range(H+2)]
    dist[a][b]=0

    while len(willgo) >=1:
        now = willgo.pop(0) #探索候補リストから優先度の高い先頭要素を取ってくる
        finish.append(now) #今いる場所を訪問済みに追加
        nextplace = [] #次に行ける所を探す
        nowh = now[0]
        noww = now[1]

        if SSS[nowh-1][noww] == ".":
            nextplace.append([nowh-1,noww])
        if SSS[nowh+1][noww] == ".":
            nextplace.append([nowh+1,noww])
        if SSS[nowh][noww-1] == ".":
            nextplace.append([nowh,noww-1])
        if SSS[nowh][noww+1] == ".":
            nextplace.append([nowh,noww+1])
        
        for n in nextplace:
            if n in finish: continue
            if n in willgo: continue
            willgo.append(n)
            dist[n[0]][n[1]]=dist[nowh][noww]+1

    return max([max(j) for j in dist])




ans = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if SSS[i][j]==".":
            ans = max(ans,maxlen(i,j))
print(ans)
