from collections import deque


def bfs(maze, x, y):
    m = [1, 0, -1, 0]
    n = [0, 1, 0, -1]
    queue = deque([])
    queue.append([x, y])
    seen = [[False] * (w + 2) for _ in range(h + 2)]
    seen[x][y] = True
    count = 0

    while queue:
        sx, sy = queue.popleft()
        if maze[sx][sy] == 'goal':
            break

        for dx, dy in zip(m, n):
            nx = sx + dx
            ny = sy + dy
            if maze[nx][ny] != '#' and not seen[nx][ny]:
                seen[nx][ny] = True
                queue.append([nx, ny])
                count += 1

    return count


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

maze = [['#'] * (w + 2)]
for i in range(h):
    maze.append(['#'] + list(map(str, input())) + ['#'])

maze.append(['#'] * (w + 2))

ans = 0
for sy in range(1, w + 1):
    for sx in range(1, h + 1):
        for gy in range(1, w + 1):
            for gx in range(1, h + 1):
                if maze[gx][gy] == '.' and maze[sx][sy] == '.':
                    maze[gx][gy] = 'goal'
                    ans = max(ans, bfs(maze, sx, sy))
                    maze[gx][gy] = '.'

print(ans)
