There are N students in a round table meeting. Each student belongs to a university given in the array , which denotes the university that the student belongs to.
There are Q queries of the form , denoting two universities. The answer to each query is the minimum time taken by any one of the student from these universities to meet each other.
Note:
Input
The first line of input contains 2 integers N and Q
The second line contains N space seperated integers denoting
Q lines follow . Each containing 2 integers x and y
Output
The output contains q lines each containing the answer to each query
CONSTRAINTS
Constraint: , The elements of the array are between 1 to
x and y are guaranteed to be present in the array
Positions : 1 2 3 4 5 6 7 8 9 10
Values : 7 1 4 3 1 6 4 2 5 1
Query 1: 3 and 4 are already adjacent , therefore answer is 0
Query 2: 1 and 2, in this case there are three 1's present
Checking the answer for all the 1's
1(at posn 2) : Answer = 2
1(at posn 5) : Answer= 1
1(at posn 10) : Answer= 1
Therefore answer=1;