Not able to pass all test cases

Check your code with this case
1 2 3 4 5 6 -1
6

It is giving wrong output.

Refer this