The beautiful city of Julcvari decided to host a city tour (online, of course). They have different attractions, the one having a beauty equal to . An initial order for the presentation of the attractions has been selected, but the people of Julcvari started worrying that it might not be the best one.
They believe that the best order for visiting the attractions is the one for which the number of pairs of attractions , where was visited before but is more beautiful than is minimised. But organizing events is not so easy, a lot of paperwork needs to be done in order to change something like this.
Task
So, the host managed to get swap plans: let , , , be an array of integers representing the swap plans. The host can perform any number of swaps on the initial order, such that the swapped positions are at a distance equal to one of the elements from array . There is not much time left, so the people of Julcvari ask you for help in finding the best order in which the attractions are presented.
In other words, a permutation of size and an array of size with distinct elements are given. You can only perform swaps between positions and such that is equal to an element of . What is the permutation with the minimum number of inversions that can be obtained?
Input data
The first line of the input contains and .
The second line of the input contains integers, representing the initial order of the attractions.
The third line of the input contains integers, representing the available swap plans.
Output data
The only line of the output should contain elements, representing the best order for showing the attractions.
Constraints and clarifications
- For tests worth points, .
- For tests worth more points, .
Example 1
stdin
8 1
1 4 3 5 7 2 8 6
8
stdout
1 4 3 5 7 2 8 6
Example 2
stdin
8 7
2 4 1 5 3 6 7 8
7 6 3 8 2 5 1
stdout
1 2 3 4 5 6 7 8