H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
INF = 10<<1000

V = H*W
maze = [[INF]*V for _ in range(V)]

#隣接行列（対角成分）
for i in range(V):
    maze[i][i] = 0

#隣接行列（経路があれば1）
for py in range(H):
    for px in range(W):
        if s[py][px] == '#': continue
        target = [(px+1, py), (px-1, py), (px, py+1), (px, py-1)]
        for x, y in target:
            if not (0<=x<W and 0<=y<H): continue
            if s[y][x] == '#': continue
            maze[W*py+px][W*y+x] = 1

#ワーシャル・フロイド
for k in range(V):
    for i in range(V):
        for j in range(V):
            maze[i][j] = min(maze[i][j], maze[i][k]+maze[k][j])

res = 0
for i in range(V):
    for j in range(V):
        if j!=INF: res = max(res, maze[i][j])
          
print(res)