| Codeforces Round 1122 (Div. 3) |
|---|
| Finished |
Vihaan built a deque on his own, but it sometimes malfunctions.
Vihaan wants the final contents of the deque, from front to back, to be $$$[1,2,\ldots,n]$$$.
You are given an array $$$b$$$ of length $$$m$$$. The elements arrive one at a time in the order $$$b_1,b_2,\ldots,b_m$$$.
Whenever an element $$$b_i$$$ arrives, Vihaan must perform exactly one of the following operations:
After all $$$m$$$ elements have arrived and all operations have been performed, the deque must contain exactly $$$[1,2,\ldots,n]$$$ in that order.
Determine the minimum number of times the deque must malfunction to create $$$[1,2,\ldots,n]$$$, or determine that it is impossible.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 2 \cdot 10^5$$$) — the length of the desired deque and the number of arriving elements.
The second line contains $$$m$$$ integers $$$b_1,b_2,\ldots,b_m$$$ ($$$1 \le b_i \le n$$$) — the order in which the elements arrive.
It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print one integer — the minimum number of times the deque must malfunction.
If it is impossible to obtain the desired deque, print $$$-1$$$.
91 31 1 13 42 1 1 24 41 4 2 34 54 3 4 2 15 81 3 2 5 4 3 1 26 61 6 5 4 3 24 61 3 2 3 4 36 82 6 3 5 2 1 4 26 81 6 2 5 1 5 3 4
0-12014023
In the first test case, Vihaan can perform the following operations:
In the second test case, the value $$$3$$$ never appears in $$$b$$$, so it is impossible to obtain the desired deque.
In the third test case, Vihaan can perform the following operations:
In the fourth test case, Vihaan can perform the following operations:
| Name |
|---|


