Problem1574--Simple search question

1574: Simple search question

[Creator : ]
Time Limit : 1 sec  Memory Limit : 128 MB

Description

Given an array of n integers, you need to answer a few queries. Each time the two integers K and V are queried, the subscript of the Kth V from left to right is output (numbered from left to right is 1~n).

Input

The input contains multiple sets of test data. Each set of data first acts as two integers n and m (1<=n, m<=100000), and the second line contains n positive integers not exceeding 10^6 as the array to be queried. The following m lines each contain two integers K and V (1 <= K <= n, 1 <= V <= 10^6).

Output

For each query, the query results are output. If it does not exist, output 0.

Sample Input Copy

5 3
1 2 1 2 1
3 1
1 2
3 2

Sample Output Copy

5
2
0

HINT

STL—map

Source/Category