Piggy recently learned about the Longest Increasing Subsequence (LIS). For an integer sequence $A = (a_1, a_2, \dots, a_k)$, a subsequence of $A$ is defined as: a sequence formed by deleting zero or more elements from $A$ (it is allowed to delete none, or all $k$ elements) and keeping the remaining elements in their original relative order. If the elements of this subsequence are strictly increasing from left to right, it is called an increasing subsequence of $A$. The increasing subsequence containing the maximum number of elements is called the Longest Increasing Subsequence of $A$. For example, $(2, 4, 5, 6)$ and $(1, 4, 5, 6)$ are both longest increasing subsequences of $(2, 1, 1, 4, 7, 5, 6)$, both with a length of 4.
Now, Piggy has encountered the following problem: given a sequence $B_m = (b_1, b_2, \dots, b_m)$, let $C$ be a subsequence of $B_m$ such that the length of the longest increasing subsequence of $C$ does not exceed $k$. What is the maximum possible length of $C$?
Piggy thinks this problem is too simple and lacks challenge, so he decided to propose a harder one. He gives you a sequence $B = (b_1, b_2, \dots, b_n)$ and several queries. Each query provides two integers $m$ and $k$. You need to answer the above problem for the sequence $B_m = (b_1, b_2, \dots, b_m)$ formed by the first $m$ elements of $B$ and the given $k$.
Input
The first line contains two integers $n$ and $q$, where $n$ is the length of sequence $B$ and $q$ is the number of queries.
The second line contains $n$ positive integers $b_1, b_2, \dots, b_n$ separated by spaces.
The next $q$ lines each contain two integers $m_i$ and $k_i$, representing a query for $m = m_i$ and $k = k_i$.
Output
Output $q$ lines, each containing one integer as the answer to the corresponding query in order.
Examples
Input 1
11 6 9 6 3 1 5 12 8 4 2 2 2 5 1 7 2 9 1 9 2 11 1 11 11
Output 1
4 6 5 8 7 11
Input 2
See the files lis/lis2.in and lis/lis2.ans in the contestant directory.
Output 2
See the files lis/lis2.in and lis/lis2.ans in the contestant directory.
Note
Query 1: For the sequence $(9, 6, 3, 1, 5)$, we can choose the subsequence $(9, 6, 3, 1)$, whose longest increasing subsequence has length 1.
Query 2: For the sequence $(9, 6, 3, 1, 5, 12, 8)$, we can choose the subsequence $(9, 6, 3, 1, 12, 8)$, whose longest increasing subsequence has length 2.
Query 3: For the sequence $(9, 6, 3, 1, 5, 12, 8, 4, 2)$, we can choose the subsequence $(9, 6, 5, 4, 2)$, whose longest increasing subsequence has length 1.
Query 4: For the sequence $(9, 6, 3, 1, 5, 12, 8, 4, 2)$, we can choose the subsequence $(9, 6, 3, 1, 12, 8, 4, 2)$, whose longest increasing subsequence has length 2.
Query 5: For the sequence $(9, 6, 3, 1, 5, 12, 8, 4, 2, 2, 2)$, we can choose the subsequence $(9, 6, 5, 4, 2, 2, 2)$, whose longest increasing subsequence has length 1.
Query 6: For the sequence $(9, 6, 3, 1, 5, 12, 8, 4, 2, 2, 2)$, we can choose the subsequence $(9, 6, 3, 1, 5, 12, 8, 4, 2, 2, 2)$, whose longest increasing subsequence has length 3.
Constraints
| Test Case | $n$ | Constraints |
|---|---|---|
| 1 | $\le 50000$ | $k_i = 1$ |
| 2 | $\le 300$ | .h=2 $k_i \le 2$ |
| 3 | $\le 3000$ | |
| 4 | .h=2 $\le 50000$ | $b_i \le 5$ |
| 5 | $b_i \le 8$ | |
| 6 | .h=2 $\le 100$ | .h=2 $m_i = n$ |
| 7 | ||
| 8 | $\le 800$ | .h=2 $m_i = n, k_i \le 10$ |
| 9 | $\le 1500$ | |
| 10 | $\le 10000$ | $m_i = n, k_i \le 30$ |
| 11 | $\le 15000$ | $m_i = n, k_i \le 40$ |
| 12 | .h=2 $\le 20000$ | $m_i = n, k_i \le 50$ |
| 13 | $k_i \ge 10000$ | |
| 14 | $\le 8000$ | $m_i = n$ |
| 15 | $\le 25000$ | .h=6 No additional constraints |
| 16 | $\le 40000$ | |
| 17 | $\le 45000$ | |
| 18 | .h=3 $\le 50000$ | |
| 19 | ||
| 20 |
For $100\%$ of the data, $1 \le n \le 50000$, $1 \le b_i \le 50000$, $1 \le q \le 200000$, $1 \le k_i \le m_i \le n$.