n, m = map(int, input().split())
g = [input() for _ in range(n)]

def bfs(r, c):
    t = [[-1] * m for v in g]
    q = []
    t[r][c] = 0
    q += (r, c),
    h = 0
    dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    while h < len(q):
        r, c = q[h]
        h += 1
        for d in range(4):
            r1, c1 = r + dirs[d][0], c + dirs[d][1]
            if 0 <= r1 < n and 0 <= c1 < m and '.' == g[r1][c1] and t[r1][c1] < 0:
                t[r1][c1] = t[r][c] + 1
                q += (r1, c1),
    ret = -1
    for v in t:
        ret = max(ret, max(v))
    return ret

ans = 0
for i in range(n):
    for j in range(m):
        if g[i][j] == '.':
            ans = max(ans, bfs(i, j))
print(ans)
