Multiplying Digits

Given base B and target N, find the smallest positive integer whose base-B digits multiply to N, or report that none exists.

Hard8Number theoryDynamic programmingGreedyMathNo attempts yetTime limit3sMemory limit512 MB

Problem

Multiply together every digit of a positive integer and you get a non-negative integer. In base 10 this rule defines a function ff. For example, f(38)=3×8=24f(38) = 3 \times 8 = 24.

The same rule works in any base. Written in base 3, the number 80 is 2222, so f3(80)=2×2×2×2=16f_3(80) = 2 \times 2 \times 2 \times 2 = 16.

Solve the reverse problem. Given a base BB and a target NN, find the smallest positive integer XX with fB(X)=Nf_B(X) = N, where fB(X)f_B(X) is the product of the digits of XX written in base BB.

Input

The first line contains two integers BB and NN separated by a space (2<B100002 < B \le 10000, 0<N<2630 < N < 2^{63}).

Output

Print, in base 10, the smallest positive integer XX with fB(X)=Nf_B(X) = N. If no such XX exists, print impossible instead. Every input for which XX exists satisfies X<263X < 2^{63}.