Matrix search test case issue

Need Help with one test case. I will share the code with you .What is missing can you guide me

for input:
4 4
10 20 30 40 15 25 35 45 27 29 37 48 32 33 39 50
29
correct output should be
1
debug for this