from copy import deepcopy
import queue

def shortestpath(y0, x0, maze, h, w):
    step_cnt = [[-1] * w for _ in range(h)]
    q = queue.Queue()
    step_cnt[y0][x0] = 0
    q.put((y0, x0))
    dy = [-1, 0, 1, 0]
    dx = [0, -1, 0, 1]
    while not q.empty():
        y, x = q.get()
        maze[y][x] = '#'
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 0 <= y_next < h and 0 <= x_next < w and maze[y_next][x_next] == '.':
                q.put((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1
                    
    return step_cnt[y][x]
 
h, w = map(int, input().split())      
maze = [[x for x in input()] for _ in range(h)]
max_steps = -1

for y0 in range(h):
    for x0 in range(w):
        if maze[y0][x0] == '#':
            continue
        copymaze = deepcopy(maze)
        max_steps = max(max_steps, shortestpath(y0, x0, copymaze, h, w))

print(max_steps)