There are chairs in a circle. Exactly of these chairs are empty and there are students numbered from to standing at some of these chairs. Every second, each student moves forward by one chair. In particular, if they are currently standing by chair , then they will move to chair after. If a student reaches an empty chair, including at the very beginning, they will sit down for the remaining time. Who will be the last standing student?
It is guaranteed that every student begins by a different chair.
Edit: The test data has been fixed.
For all subtasks, all the indices in the input will be between and inclusive.
Subtask 1 [30%]
Subtask 2 [50%]
Subtask 3 [20%]
The first line will have two space-separated integers, and .
The next line will have space-separated integers representing the indices of the empty chairs.
The third line will have space-separated integers. The integer is the chair at which student begins at.
Output a single integer, the index of the last standing student.
7 2 2 1 6 5 4