cho.sh
Notes
Loading...

Difference from Reversal

Time limit

2s

Memory limit

128 MB

Problem

For a nonnegative integer, define its reversal as the integer obtained by reading its decimal digits from right to left. Any zeros that become leading zeros after the reversal disappear when the value is interpreted as an integer.

Given a natural number D, find the smallest nonnegative integer x such that x - reverse(x) = D. Here, reverse(x) denotes the reversal of x.

Input

D is given. D is a natural number not greater than 1,000,000.

Output

Print the smallest x satisfying the condition. If no such x exists, print -1.