Prime Palindrome Flags

No attempts yetTime limit1sMemory limit128 MB

Problem

At the athletics festival of J Middle School, each class plays the following class-versus-class contest. A class chooses $n$ boy–girl representative pairs

$$(b_1, g_1),\ (b_2, g_2),\ \dots,\ (b_n, g_n).$$

Every student freely chooses a flag printed with a single digit from $0$ to $9$ (there are plenty of flags of each digit) and they line up in one horizontal row. The two students of a pair must hold flags showing the same digit, so $g_i = b_i$. The row is ordered as

$$b_1\ b_2\ \dots\ b_n\ \ c\ \ g_n\ \dots\ g_2\ g_1,$$

that is, the girls stand in the reverse order of the boys. In the middle, the homeroom teacher either stands holding a flag whose digit $c$ is fixed in advance by the head referee, or is told not to stand at all.

Reading the whole row of digits from left to right as a single integer — it has $2n$ digits (no teacher) or $2n+1$ digits (with the teacher) — the class whose integer is prime wins. If both integers are prime, or both are non-prime, the class with the larger integer wins. A leading zero is not allowed (numbers are written in the usual way), so arrangements such as

$$0\ b_2\ \dots\ b_n\ c\ g_n\ \dots\ g_2\ 0$$

or

$$0\ b_2\ \dots\ b_n\ g_n\ \dots\ g_2\ 0$$

are forbidden; hence $b_1 \neq 0$.

Because $g_i = b_i$, the row of digits is a palindrome $b_1 b_2 \dots b_n,[c],b_n \dots b_2 b_1$. You want your class to never lose. Determine the arrangement that guarantees you do not lose.

Against optimal play the never-losing arrangement is unique. If at least one valid palindrome is prime, it is the largest prime palindrome (a prime always beats a non-prime, and among primes only the largest never loses); otherwise every palindrome is non-prime and it is the largest palindrome.

Input

A single line contains the integer $n$ and the single-digit integer $c$, separated by one space. If $c < 0$, the teacher does not stand in the middle (the integer then has $2n$ digits); otherwise the teacher stands with the digit $c$ (the integer has $2n+1$ digits).

Constraints: $1 \le n$ and $-9 \le c \le 9$. In most cases $1 \le n \le 4$.

Output

Print, on a single line, the never-losing arrangement — the row of digits read as one integer.