#abc301d. [abc301_d]Bitmask
[abc301_d]Bitmask
Problem Statement
You are given an integer and a string consisting of 0
, 1
, and ?
. Let be the set of values that can be obtained by replacing each ?
in with 0
or 1
and interpreting the result as a binary integer. For instance, if ?0?
, we have $T=\\lbrace 000_{(2)},001_{(2)},100_{(2)},101_{(2)}\\rbrace=\\lbrace 0,1,4,5\\rbrace$.
Print (as a decimal integer) the greatest value in less than or equal to . If does not contain a value less than or equal to , print -1
instead.
Constraints
- is a string consisting of
0
,1
, and?
. - The length of is between and , inclusive.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
?0?
2
Sample Output 1
1
As shown in the problem statement, . Among them, and are less than or equal to , so you should print the greatest of them, .
Sample Input 2
101
4
Sample Output 2
-1
We have , which does not contain a value less than or equal to .
Sample Input 3
?0?
1000000000000000000
Sample Output 3
5