#P10697. Missing Digit Rank

    ID: 12727 Type: Default 1000ms 256MiB

Missing Digit Rank

Missing Digit Rank

uuku is learning digit DP. One day, he discovered that among the nine digits \(1,2,\ldots,9\), a specific digit \(x\) has disappeared. That is, all numbers that contain the digit \(x\) vanish from the set of natural numbers.

This disappearance has a huge impact on counting numbers. Now, given a natural number \(n\) and the missing digit \(x\), your task is to determine the rank of \(n\) among the remaining natural numbers when they are sorted in increasing order.

Note: If \(n\) itself contains the digit \(x\), then it is not present in the remaining set. In such a case, output \(-1\).

inputFormat

The input consists of a single line containing two integers \(x\) and \(n\), where \(x\) is the missing digit (from 1 to 9) and \(n\) is a natural number.

outputFormat

Output a single integer representing the rank of \(n\) among the natural numbers that do not contain the digit \(x\) when sorted in increasing order. If \(n\) itself is removed because it contains \(x\), output \(-1\).

sample

5 12
11