Not able to understand Why WA!

https://www.codechef.com/viewsolution/34620457
Here is my code , I think my logic is correct but still it is showing Error
Please help!!

Try the case
5 3
3 4 5 6 7
Your code will output 4 whereas it should be -1.

You have to make sure that all positive integers from 1 to m - 1 are present otherwise the answer would be -1. If they are present, the answer would be m-1 + the number of integers greater than m present in the array.