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


def clear_maze(sx, sy, maze):

    # debug_print(maze)

    INF = 100000000

    field_x_length = len(maze[0])
    field_y_length = len(maze)
    distance = [[INF for i in range(field_x_length)]
                for j in range(field_y_length)]
    #    distance = [[None]*field_x_length]*field_y_length
    for i in range(field_y_length):
        for j in range(field_x_length):
            if maze[i][j] == '#':
                distance[i][j] = -100

    def bfs():
        queue = []

        queue.insert(0, (sx, sy))

        distance[sy][sx] = 0

        while len(queue):
            x, y = queue.pop()

            flag = False
            for i in range(field_y_length):
                if INF in distance[i]:
                    flag  = True
                    break
                else:
                    continue
            if flag is False:
                break
                
    

            # if x == gx and y == gy:
            #     break

            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]

                if (0 <= nx and nx < field_x_length and 0 <= ny and ny < field_y_length and maze[ny][nx] != '#' and distance[ny][nx] == INF):
                    queue.insert(0, (nx, ny))
                    distance[ny][nx] = distance[y][x] + 1
        
        return distance

    return bfs()


S = [list(input()) for _ in range(h)]
# print(S)

ans = 0


# def pick_max(maze):
#     field_x_length = len(maze[0])
#     field_y_length = len(maze)
#     ans = 0
#     for i in ra

for i in range(h):
    for j in range(w):
        start = S[i][j]
        if start == '#':
            continue

        # for k in range(h):
        #     for l in range(w):
            
        num = clear_maze(j, i, S)
        for i in range(h):
            ans = max(ans, max(num[i]))
        # print(an)
print(ans)
