A few guidelines first:
Now, try running your solution locally on given test case. ie.
1 9
You are not taking 9 as input and 0 is being printed for this test. How can it proceed further ?