One test case failing

it’s failing the test case-1 i have also checked somewhere else approach is almost same pls check once

link - https://www.codepile.net/pile/Z7gK9O7p

debug for this:
5
3
4
5
1
2
2
Correct output:
4
Your output:
-1