H,W = map(int, input().split())
S = [list('#'+input()+"#") for i in range(H)]
S.insert(0, list('#'*(W+2)))
S.append(list('#'*(W+2)))
vector = [(1,0), (-1,0), (0,1), (0,-1)]
ans = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=='.':
            Q = [(i,j)]
            distance = [[0]*(W+2) for i in range(H+2)]
            distance[i][j] = 1
            while Q!=[]:
                x,y = Q.pop(0)
                for k in vector:
                    x1,y1 = x+k[0],y+k[1]
                    if S[x1][y1]=='.' and distance[x1][y1]==0:
                        Q.append((x1,y1))
                        distance[x1][y1] = distance[x][y] + 1
            for i in range(H+2):
                for j in range(W+2):
                    ans = max(ans, distance[i][j])
print(ans-1)