---
{"category_name":"easy","problem_code":"CROSBLK","problem_name":"Crossing Blocks","problemComponents":{"constraints":"- $1 \\leq T \\leq 100$\n- $2 \\leq N \\leq 10^5$\n- $0 \\leq A_i \\leq 10^5$ for each valid $i$\n- the sum of $N$ over all test cases does not exceed $10^6$\n","constraintsState":true,"subtasks":"**Subtask #1 (30 points):**\n- $2 \\leq N \\leq 1,000$\n- the sum of $N$ over all test cases does not exceed $5 \\cdot 10^4$\n\n**Subtask #2 (70 points):** original constraints\n","subtasksState":true,"inputFormat":"- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.\n- The first line of each test case contains a single integer $N$.\n- The second line contains $N$ space-separated integers $A_1, A_2, \\ldots, A_N$.","inputFormatState":true,"outputFormat":"For each test case, print a single line containing one integer --- the minimum number of moves or $-1$ if it is impossible to reach the last block.","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"2\n5\n9 15 8 13 8\n9\n20 16 13 9 17 11 15 8 7","output":"-1\n4","explanation":"**Example case 1:** There is no way to move from the first block (with height $9$) to any other block.\n\n**Example case 2:** The only sequence of $4$ moves is $20 \\rightarrow 17 \\rightarrow 15 \\rightarrow 8 \\rightarrow 7$. For example, in the first move, all the heights between $20$ and $17$ do not exceed $17$, so all conditions are satisfied.\n","isDeleted":false}}},"video_editorial_url":"https://youtu.be/SJo0OQbttQY","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":0.5,"source_sizelimit":50000,"problem_author":"rahularya1","problem_tester":"","date_added":"25-08-2021","tags":{"0":"ad","1":"easy","2":"ltime99","3":"rahularya1"},"problem_difficulty_level":"Easy","best_tag":"Ad Hoc","editorial_url":"https://discuss.codechef.com/problems/CROSBLK","time":{"view_start_date":1630170002,"submit_start_date":1630170002,"visible_start_date":1630170002,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=CROSBLK","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Mandarin](https://www.codechef.com/download/translated/LTIME99/mandarin/CROSBLK.pdf), [Bengali](https://www.codechef.com/download/translated/LTIME99/bengali/CROSBLK.pdf), [Russian](https://www.codechef.com/download/translated/LTIME99/russian/CROSBLK.pdf), and [Vietnamese](https://www.codechef.com/download/translated/LTIME99/vietnamese/CROSBLK.pdf) as well.
Chef is very adventurous, so he asked Bob to give him a task.
Bob gave him a sequence of blocks with heights $A_1, A_2, \ldots, A_N$. Chef is at the first block and he has to reach the $N$-th block using the minimum number of moves to complete the task.
In one move, he can jump from the $i$-th block to the $j$-th block only if the following conditions are satisfied:
- $i \lt j$
- $A_i \geq A_j$
- for all $k$ ($i \lt k \lt j$), $A_k \leq A_j$
You have to find the minimum number of moves Chef needs to perform to reach the last block, or determine that it is impossible.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>