Comments

try this test case:

5 1
5 4 3 2 6
2 5

right answer will be 3. but your code gives 4