h, w = map(int, input().split())

M = [str(input()) for _ in range(h)]
M = ['#'*w] + M + ['#'*w]
M = ['#'+c+'#' for c in M]

from collections import deque
ans = 0
for sy in range(1, h+1):
    for sx in range(1, w+1):
        q = deque()
        q.append((sy, sx))
        visit = [[-1]*(w+2) for _ in range(h+2)]
        visit[sy][sx] = 0
        while q:
            y, x = q.popleft()
            for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):
                ny, nx = y+dy, x+dx
                if visit[ny][nx] == -1 and M[ny][nx] != '#':
                    visit[ny][nx] = visit[y][x]+1
                    q.append((ny, nx))
        ans = max(ans, max([max(row) for row in visit]))
print(ans)