from collections import deque
dxdy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        d = [[-1] * w for _ in range(h)]
        q = deque([(i, j)])
        d[i][j] = 0
        while q:
            y, x = q.popleft()
            for dx, dy in dxdy:
                if 0 <= x + dx < w and 0 <= y + dy < h and s[y + dy][x + dx] == '.' and d[y + dy][x + dx] == -1:
                    q.append((y + dy, x + dx))
                    d[y + dy][x + dx] = d[y][x] + 1
        for row in d:
            ans = max(ans, max(row))
print(ans)