Under construction

Still being built. Things may change

Difference from Reversal

Time limit2sMemory limit128 MB

Summary
Find the smallest nonnegative integer x whose value minus its decimal reversal equals a given natural number D, or report that none exists.
Level

Medium7 of 10

Topics
Math, Brute force, Number theory, Implementation
Solved
No attempts yet

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.

Examples7

  1. Example 1

    Input
    18
    
    Expected output
    20
    
  2. Example 2

    Input
    15
    
    Expected output
    -1
    
  3. Example 3

    Input
    4275
    
    Expected output
    5080
    
  4. Example 4

    Input
    900
    
    Expected output
    101001
    
  5. Example 5

    Input
    1989
    
    Expected output
    100990
    
  6. Example 6

    Input
    857232
    
    Expected output
    860300
    
  7. Example 7

    Input
    45
    
    Expected output
    50