Juggling tennis balls not only strengthens the cardiovascular and muscular system and stabilizes the spirit, but also helps to dynamically model persistent data structures...
(Sergey Kopeliovych — from an unspoken lecture)
Sergey is a system administrator at a large company. His responsibilities include backing up information stored on various servers and rolling back to previous versions if problems arise.
Currently, Sergey is facing an issue with insufficient storage space for backup information. He decided to move part of this data to new servers. Unfortunately, if something goes wrong during the transfer, he will not be able to perform a rollback, so the transfer procedure must be carefully planned.
At present, Sergey stores recovery points for different servers, numbered from to . The recovery point with number allows rollback for server a_i. Sergey decided to split the transfer into stages, so that at each stage, in case of problems, recovery points numbered , l + 1, , for some and will be available.
In order to optimally plan the data transfer, Sergey needs to answer queries: for a given , what is the minimum such that during the transfer, recovery points for at least different servers will be available?
Help Sergey.
The first line of input contains two integers and separated by a space — the number of recovery points and the number of servers (1 \leq n,\ m \leq 100\,000).
The second line contains integers a_1, a_2, \ldots, a_n — the server numbers to which the recovery points correspond (1 \leq a_i \leq m).
The third line contains — the number of queries to process (1 \leq q \leq 100\,000).
While processing the queries, you must maintain a number , which is initially . Each query is specified by a pair of numbers x_i and y_i. Use these to compute the query data as follows:
Let the answer to the -th query be . After completing this query, assign the value .
For each query, print a single number — the required minimum , or 0 if such does not exist.
Ejemplo 1