h, w = map(int, input().split())
meiro = []
for i in range(h):
    line = input()
    meiro.append(line)


def dfs(y, x):
    dist = [[-1]*w for _ in range(h)]
    if meiro[y][x] == '#':
        return 0
    dist[y][x] = 0

    pattern = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    todo = []
    for dy, dx in pattern:
        ny, nx = y + dy, x + dx
        if 0 <= ny <= h-1 and 0 <= nx <= w-1:
            todo.append([ny, nx, 1])

    while todo:
        y, x, d = todo.pop()
        if meiro[y][x] == '#':
            continue
        if dist[y][x] != -1:
            if dist[y][x] <= d:
                continue

        dist[y][x] = d
        for dy, dx in pattern:
            ny, nx = y + dy, x + dx
            if 0 <= ny <= h - 1 and 0 <= nx <= w - 1:
                todo.append([ny, nx, d+1])

    res = 0
    for line in dist:
        res = max(max(line), res)

    return res


ans = []
for y in range(h):
    for x in range(w):
        ans.append(dfs(y, x))

print(max(ans))
