Consider an inifite array, , of positive numbers, , where each . You can apply a permutation, , of size (i.e., different numbers ) to the -element subset of your array from through in the following way:
To get infinite array , you must apply permutation to the first elements ( to ), then to elements through , then to elements through , and so on, infinitely many times.
Given the values of , , and , find and print the value of . See the Explanation section below for more detail.
Note: This challenge uses -based array indexing.
Input Format
The first line contains space-separated integers, and , respectively.
The second line contains space-separated integers describing the respective values of .
Constraints
- , and each is unique.
Output Format
Print a single integer denoting the value of .
Sample Input 0
2 10
2 1
Sample Output 0
11
Sample Input 1
3 1
2 3 1
Sample Output 1
2
Sample Input 2
3 10
2 3 1
Sample Output 2
10
Explanation
Sample Case 0 has the following sequence of array transformations:
As you can see, each . Thus, we know that .
Sample Case 1 and Sample Case 2 have the following sequence of array transformations:
As you can see, and .