Minimum value

No attempts yetTime limit1sMemory limit256 MB

Problem

You are given NN integers in order (1N100,0001 \le N \le 100{,}000). Finding the smallest value from the aa-th integer through the bb-th integer is not hard. It becomes a harder problem once MM such pairs aa, bb are given (1M100,0001 \le M \le 100{,}000). Solve it.

Here the aa-th means the aa-th in input order. For example, if a=1a = 1 and b=3b = 3, find the minimum among the 1st, 2nd and 3rd integers in input order. Each integer is between 1 and 1,000,000,000.

Input

The first line contains NN and MM. Each of the next NN lines contains one integer. Each of the following MM lines contains aa and bb separated by a space (1abN1 \le a \le b \le N).

Output

Print the answer for each aa, bb on its own line, in the order the pairs were read, for a total of MM lines.