Vampire Numbers

Time limit10sMemory limit128 MB

Problem

$1827$ is an interesting number because $1827 = 21 \times 87$, and the digits used on the left-hand side and the right-hand side are exactly the same. $136948$ has a similar property: $136948 = 146 \times 938$.

Numbers like these are called vampire numbers. That is, for $v$ to be a vampire number it must be possible to write it as a product of two numbers $a$ and $b$ ($v = a \times b$) such that the digits appearing in $a$ and $b$ together are exactly the digits of $v$, counting repetitions. None of $v$, $a$, $b$ may have a leading zero.

Because $a$ and $b$ would normally have to be the same length, $v$ would have to have an even number of digits; but in this problem, $a$ and $b$ having different lengths is also allowed for a vampire number.

Here are some examples of vampire numbers.

$126 = 6 \times 21$

$10251 = 51 \times 201$

$702189 = 9 \times 78021$

$29632 = 32 \times 926$

Given a number $X$, write a program that finds the smallest vampire number greater than or equal to $X$.

Input

The input consists of several test cases. Each test case is a single line containing an integer $X$ ($10 \le X \le 1{,}000{,}000$). The input ends with a line containing $0$.

Output

For each test case, output the smallest vampire number greater than or equal to $X$, one per line.

Hint

Vampire numbers are a genuine mathematical concept (see Wikipedia: Vampire number).