Younghoon the Prankster

Given a digit string where 1 and 6 are interchangeable and 2 and 7 are interchangeable, print its k-th candidate in lexicographic order or -1.

Easy3CombinatoricsStringInterviewNo attempts yetTime limit1sMemory limit128 MB

Problem

Heehyun has one password that she uses for her internet accounts. The password is so long that she writes it on a slip of paper and carries the slip around to check it. Younghoon, who likes pranks, took the slip and turned some of the 1s into 6s, some of the 6s into 1s, some of the 2s into 7s, and some of the 7s into 2s.

The slip alone is now useless. A digit written as 1 was originally 1 or 6, and a digit written as 6 was also originally 1 or 6. The same holds for 2 and 7. The remaining digits 0, 3, 4, 5, 8, 9 were left alone, so they are unchanged.

Heehyun prepared for this. Her clue is this: replace each 1 or 6 in the slip with 1 or 6 and each 2 or 7 with 2 or 7, list every number you can build this way in lexicographic order, and the k-th entry of that list is the original password. All candidates have the same length, so lexicographic order compares them digit by digit from the left.

Given the slip and k, find the original password.

Input

The first line contains the password as Younghoon left it. It is 1 to 60 digits long and consists of digits only. Its first digit may be 0.

The second line contains an integer k (1k26311 \le k \le 2^{63} - 1).

Output

Print the original password on the first line.

If the k-th candidate does not exist, print -1.