A student named Vasily had to solve the following problem during his Unified State Exam in Computer Science.
Executor $$$A17$$$ works with three commands numbered $$$1$$$ through $$$3$$$:
The first command adds $$$1$$$ to the number on the screen, the second one adds $$$x$$$, and the third one multiplies it by $$$7$$$.
Program for Executor $$$A17$$$ contain a sequence of commands numbered $$$1$$$ through $$$3$$$. Executor $$$A17$$$ transforms the number on the screen in accordance with the given sequence of commands. The first value is always $$$1$$$. The final result of running the program is $$$N$$$.
After pondering on the subject for a while, Vasily calculated the value of $$$K$$$ – number of program options for Executor $$$A17$$$ resulting in a certain number $$$N$$$. For example, when $$$x = 5, N = 7$$$, the number of options $$$K = 4$$$ (numbers of commands):
After the exam, Vasily started wondering how to calculate the number $$$x$$$ based on input data $$$N$$$ and $$$K$$$.
Write a program that will determine the smallest number x meeting the problem's requirements based on given numbers $$$N$$$ and $$$K$$$.
The first line of the input file contains two positive integers $$$N$$$ and $$$K$$$ ($$$0 \lt N \le 10^4, 0 \lt K \le 2^{60}$$$) separated by a space.
The output file must contain a single number $$$x$$$ ($$$1 \lt x \lt N$$$) – the smallest possible number meeting the requirements, if such number exists, otherwise output file must contain 0.
7 4
5
14 3
0
| Название |
|---|


