Natalie has mastered counting from to
on her fingers. With
fingers in each of
hands, this may seem like the limit, but with her immense intelligence, she realized she could count even further using concatenation!
For example, Natalie can hold up finger on her left hand and
fingers on her right hand to represent the number
. By ensuring that she separates her hands far enough, this representation will not be confused with
. With this technique, Natalie can count starting from
all the way up to
, since
is the smallest number that cannot be expressed in this way.
Natalie has also begun making friends in primary school, and she has told everybody of her counting technique, making her the coolest kid in the class. With the help of her followers and a lot of teamwork, they can count together with a total of hands, ordered from left to right. Each hand can hold anywhere from
to
fingers up.
To generalize Natalie's counting technique, she can choose to partition the hands into some number of contiguous groups. Adjacent groups will be separated sufficiently to indicate concatenation. The final represented number will be the concatenation of the total number of fingers in each contiguous group, from left to right. Addition is always done before concatenation, and leading zeros are permitted.
For example, could be represented on
hands as
, and
could be represented on
hands as
.
Natalie and her friends are trying to count starting from . Can you help them determine the smallest number greater than or equal to
that cannot be represented on
hands?
Constraints
Subtask 1 [30%]
Subtask 2 [70%]
Input Specification
The first line contains one integer, , the number of hands.
The next line contains one integer, , the number that Natalie and her friends will try to start counting from.
Output Specification
Output one line containing one integer, the smallest number greater than or equal to that cannot be represented using
hands.
Sample Input 1
2
1
Sample Output 1
16
Explanation for Sample 1
This is the example described in the problem statement.
Sample Input 2
5
1
Sample Output 2
666
Explanation for Sample 2
It can be shown that all numbers from to
can be represented on
hands.
For example, can be represented on
hands as
,
can be represented as
,
can be represented as
, and
can be represented as
.
It can be shown that cannot be represented on
hands. Thus, it is the smallest number greater than or equal to
which cannot be represented on
hands.
Sample Input 3
5
148293
Sample Output 3
148293
Explanation for Sample 3
In this sample, Natalie and her friends are trying to count starting from . However,
already cannot be represented on
hands! Thus,
is the smallest number greater than or equal to
which cannot be represented on
hands.
Sample Input 4
15
31415926535
Sample Output 4
31415926666
Comments