Contain - June Long Challenge

Here is a solution for the problem CONTAIN in June Challenge. Its giving me error in some test cases and I’m not able to figure it out. Please if you can help,here is the link to the code.
https://www.codechef.com/viewsolution/34511304

1
6 1
0 0
0 3
3 0
0 1
2 0
1 2
1 1

Your code fails on this test case.
Expected Answer - 1
Your Output - 2

Dry run it and you can easily spot the problem.