#P445. 【例78.3】回文数(Noip1999)

【例78.3】回文数(Noip1999)

Description

A number (with non-zero first digit) that reads the same from left to right and right to left is called a palindrome. For example, given a decimal number 5656, adding 5656 and 6565 (reading 5656 from right to left) gives 121121, which is a palindrome. Another example, for decimal number 8787:
STEP1: 8778=16587+78= 165
STEP2: 165561=726165+561= 726
STEP3: 7266271353726+627=1353
STEP4: 1353+3531=48841353+3531=4884
Here, a step means performing one addition in base NN. In the above example, it took at least 44 steps to get the palindrome 48844884.
Write a program that, given a number MM in base NN (2N102 < N \le 10 or N=16N=16), finds the minimum number of steps needed to obtain a palindrome. If it's impossible to get a palindrome within 3030 steps (inclusive), output "Impossible".

Input Format

The first line contains a number NN (2N102< N≤10 or N=16N=16) representing the base;
The second line contains a number MM in base NN.

Output Format

The minimum number of steps needed. If it's impossible to get a palindrome within 3030 steps (inclusive), output "Impossible".

Sample

9
87
6