chef and strange matrix wrong answer

http://www.codechef.com/viewsolution/3898907
what is wrong in it

1 5 3

1 2
1 4
1 5

For the input given above output must be 5. But your code prints -1

i corrected that…but it is still showing wrong answer
http://www.codechef.com/viewsolution/3900322