from collections import deque
def main():
    H,W = map(int, input().split())
    S = [[0]*W for _ in range(H)]
    for i in range(H):
        # 1は道,0は壁
        tmp = list(map(lambda x:1 if x=='.' else 0, input()))
        S[i] = tmp
    # BFS
    ans = 0
    for i in range(H):
        for j in range(W):
            # (i,j)がスタート地点
            dist = [[-1]*W for _ in range(H)]
            dist[i][j] = 0
            que = deque([(i,j)])
            while que:
                si,sj = que.pop()
                for r,b in [(1,0),(0,1),(-1,0),(0,-1)]: # 右,下,左,上(移動方向)
                    gi = si+r
                    gj = sj+b
                    # 枠外
                    if gi<0 or (H-1)<gi or gj<0 or (W-1)<gj:
                        continue
                    # 壁
                    if S[gi][gj] == 0:
                        continue
                    # 探索済み
                    if dist[gi][gj]!=-1:
                        continue
                    dist[gi][gj] = dist[si][sj]+1
                    que.appendleft((gi,gj))
            ans = max(ans,max([max(d) for d in dist]))
    print(ans)

main()
