#P11080. Harmonious Photo Arrangement

    ID: 13137 Type: Default 1000ms 256MiB

Harmonious Photo Arrangement

Harmonious Photo Arrangement

In order to achieve a more harmonious color composition in his photograph, the photographer requires that exactly \(m\) students appear in the photo, and that the colors of their uniforms follow a given order. Each student belongs to a delegation identified by a unique number and has a uniform of a specific color.

Your task is to write a program that, given the desired color sequence, selects exactly \(m\) delegations so that each chosen delegation has the uniform color matching the corresponding position in the sequence. Each delegation can be selected at most once. If such an arrangement is possible, output the delegation numbers in the order corresponding to the desired photo positions. Otherwise, output -1.

inputFormat

The first line contains two integers n and \(m\) separated by a space, where n is the number of available delegations and \(m\) is the required number of students in the photo.

The second line contains \(m\) strings representing the desired color sequence (in order).

Each of the following \(n\) lines contains a delegation's information in the format: id color, where id is an integer representing the delegation number and color is a string representing the uniform color.

outputFormat

If an arrangement is possible, output a single line with \(m\) integers separated by spaces representing the selected delegation numbers in the photo order. Otherwise, output -1.

sample

5 3
red blue green
1 red
2 green
3 blue
4 blue
5 green
1 3 2