Debugging Permutation Split problem.

Hi! I attempted this problem. I compare the elements of the two arrays and if they are unequal, I increase the split count and if they are equal, I just increase the count by 1 till I come to the point they are unequal now. Here is my solution. It is incorrect but I cannot debug it. Kindly help me with it. https://www.codechef.com/viewsolution/23440892

The problem is here:

Got it.
1 2 3 4 5->p
4 5 1 2 3->q
This should give answer as 2 but code gives 5.