carvans wrong answer

I have run this code against as many test examples I could fine and my answers match the test results.
please help ,thanks in advance link to problem

I believe I found a case in which your program fails to produce the correct output. I will simply list it here and leave it to you to adjust your code.

Try this case:
10000 1 2 3

Your result: 1
Correct result: 2

Just to understand the problem I went ahead and coded it up quickly in python and got AC if you want to see how I approached it check out my submissions here I also have a correct submissions in C/C++.

Hope it helps!

-Michael Feliciano