import copy

H, W = map(int, input().split(' '))
maze = []
for i in range(H):
    maze.append(input())


def search(visit, queue):
    while len(queue) > 0:
        x, y, d = queue.pop(0)
        index = y * W + x
        visit[index] = d
        # top
        if y > 0 and visit[index - W] == 0 and maze[y - 1][x] == '.':
            queue.append((x, y - 1, visit[index] + 1))
        # left
        if x > 0 and visit[index - 1] == 0 and maze[y][x - 1] == '.':
            queue.append((x - 1, y, visit[index] + 1))
        # right
        if x < W - 1 and visit[index + 1] == 0 and maze[y][x + 1] == '.':
            queue.append((x + 1, y, visit[index] + 1))
        # bottom
        if y < H - 1 and visit[index + W] == 0 and maze[y + 1][x] == '.':
            queue.append((x, y + 1, visit[index] + 1))


best = 0
zero = [0 for _ in range(H * W)]
for i in range(H):
    for j in range(W):
        #visit = np.zeros((H, W), dtype=np.int32)
        visit = copy.copy(zero)
        search(visit, [(j, i, 1)])
        dist = max(visit)
        if dist > best:
            best = dist
print(best - 1)