h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
from collections import deque
def bfs(sy, sx, gy, gx):
    d = [[-1] * w for _ in range(h)]
    que = deque([[sy, sx]])
    d[sy][sx] = 0
    while que:
        y, x = que.popleft()
        if y == gy and x == gx:
            break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + j, x + k
            if 0 <= nx < w and 0 <= ny < h and d[ny][nx] == -1 and maze[ny][nx] != "#":
                d[ny][nx] = d[y][x] + 1
                que.append([ny, nx])
    return d[gy][gx]

ans = 0
for gy in range(h):
    for gx in range(w):
        for sy in range(h):
            for sx in range(w):
                ans = max(ans, bfs(gy, gx, sy, sx))
print(ans)
