You are given an array of positive integers a=[a_1,a_2,\ldots,a_n].
In one operation, you may choose any non-empty subarray [l,r] whose current values are all equal, that is,
and any positive integer . Then, for every l \le i \le r, perform
You need to answer independent queries.
Each query is given by two numbers and . For this query, you need to turn into zeros exactly those elements of the array whose initial values belong to the segment .
That is, after performing all operations, the following must hold:
for all positions such that initially L\le a_i\le R, and the values of all other elements must remain the same as before the operations.
For each query, find the minimum possible number of operations.
Each query is considered independently: after a query is finished, the initial array does not change.
The first line contains two integers and (1\le n,q\le 3\cdot 10^5) — the number of array elements and the number of queries, respectively.
The second line contains integers a_1,a_2,\ldots,a_n (1\le a_i\le 10^6).
Each of the next lines contains two integers and (1\le L\le R\le 10^6) — the value bounds for the corresponding query.
For each query, output one integer — the minimum number of operations required so that all elements whose initial values belong to the segment become equal to zero, while all other elements do not change.
Print the answers to the queries on separate lines.
Example 1
In the first query, we need to make zero all elements whose initial values belong to the range . These are the elements at positions 2,3,4,5 with values
This can be done in operations:
subtract from the subarray ;
subtract from the subarray ;
subtract from the subarray .
Before each operation, all values in the chosen subarray are equal. After these operations, all required elements are equal to zero, while all other elements remain unchanged. Fewer operations are not sufficient, so the answer is .
In the second query, [L,R]=[1,7], so we need to make all elements of the array equal to zero. This can be done in operations, for example:
subtract from the subarray ;
subtract from the subarray ;
subtract from the subarray ;
subtract from the subarray ;
subtract from the subarray ;
subtract from the subarray .
Therefore, the answer to the second query is .
In the third query, [L,R]=[4,4]. There is no element with initial value in the array, so no operations are needed. The answer is .
Subtask ( points): L = R for all queries.
Subtask ( points): a_i \le 2 for all 1 \le i \le n.
Subtask ( points): a_i \le a_{i+1} for all 1 \le i < n, n,q \le 1000.
Subtask ( points): n,q \le 1000.
Subtask ( points): R = n for all queries.
Subtask ( points): a_i \le a_{i+1} for all 1 \le i < n.
Subtask ( points): No additional constraints.