from collections import deque

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

board = []
for row in range(h):
    board.append(list(input()))

def bfs(row, col):
    max_path = 0
    queue = deque([(row, col)])
    visited[row][col] = 0
    while queue:
        next = queue.popleft()
        if next[0] < h-1 and visited[next[0]+1][next[1]] == -1 and board[next[0]+1][next[1]] == ".":
            visited[next[0]+1][next[1]] = visited[next[0]][next[1]] + 1
            if visited[next[0]][next[1]] + 1 > max_path:
                max_path = visited[next[0]][next[1]] + 1
            queue.append((next[0]+1, next[1]))
        if next[0] > 0 and visited[next[0]-1][next[1]] == -1 and board[next[0]-1][next[1]] == ".":
            visited[next[0]-1][next[1]] = visited[next[0]][next[1]] + 1
            if visited[next[0]][next[1]] + 1 > max_path:
                max_path = visited[next[0]][next[1]] + 1
            queue.append((next[0]-1, next[1]))
        if next[1] < w-1 and visited[next[0]][next[1]+1] == -1 and board[next[0]][next[1]+1] == ".":
            visited[next[0]][next[1]+1] = visited[next[0]][next[1]] + 1
            if visited[next[0]][next[1]] + 1 > max_path:
                max_path = visited[next[0]][next[1]] + 1
            queue.append((next[0], next[1]+1))
        if next[1] > 0 and visited[next[0]][next[1]-1] == -1 and board[next[0]][next[1]-1] == ".":
            visited[next[0]][next[1]-1] = visited[next[0]][next[1]] + 1
            if visited[next[0]][next[1]] + 1 > max_path:
                max_path = visited[next[0]][next[1]] + 1
            queue.append((next[0], next[1]-1))
    return max_path

result = 0
for i in range(h):
    for j in range(w):
        visited = [[-1]*w for _ in range(h)]
        max_path = bfs(i, j)
        if result < max_path:
            result = max_path

print(result)
