Finding CB Number

One test case is failing. Please tell the error or provide the test case.

for the input
5
81615
output should be 2
debug for this