from collections import deque

H, W = map(int, input().split())
c = [list(input()) for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

ans = 0
for i in range(H):
    for j in range(W):
        if c[i][j] == '.':
            sx, sy = (j, i)
            s = [[-1] * W for _ in range(H)]
            d = [[0] * W for _ in range(H)]

            que = deque([])
            que.append((sx, sy))
            s[sy][sx] = 1
            
            while que:
                x, y = que.popleft()
                s[y][x] = 1

                for k in range(4):
                    nx = x + dx[k]
                    ny = y + dy[k]

                    if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != 1 and c[ny][nx] == '.':
                        que.append((nx, ny))
                        d[ny][nx] = d[y][x] + 1
        ans = max(ans, max([max(v) for v in d]))

print(ans)
