ICPC 2016 · Problem E · Forever Young

40th ICPC · Phuket, Thailand

Statement

Time limit: 1 second

My birthday is coming up. Alas, I am getting old and would like to feel young again. Fortunately, I have come up with an excellent way of feeling younger: if I write my age as a number in an appropriately chosen base bb, then it appears to be smaller. For instance, suppose my age in base 1010 is 3232. Written in base 1616 it is only 2020!

However, I cannot choose an arbitrary base when doing this. If my age written in base bb contains digits other than 00 to 99, then it will be obvious that I am cheating, which defeats the purpose. In addition, if my age written in base bb is too small then it would again be obvious that I am cheating.

Given my age yy and a lower bound on how small I want my age to appear, find the largest base bb such that yy written in base bb contains only decimal digits, and is at least when interpreted as a number in base 1010.

Input

The input consists of a single line containing two base 10 integers yy (10y101810 \le y \le 10^{18} – yes, I am very old) and (10y10\le ℓ\le y).

Output

Display the largest base bb as described above.

Sample Input 1

32 20

Sample Output 1

16

Sample Input 2

2016 100

Sample Output 2

42

ACM-ICPC World Finals 2016 Problem E: Forever Young

No official solution in the source collection.