### Indian National Olympiad in Informatics

### Online Programming Contest, 24-25 December 2005

### Basic Division

Problem 2: Palindrome Generator, *(K Narayan Kumar, CMI)*

A palindrome is a number that reads the same whether you read it
from left to right or from right to left. Here is a surprising fact.
Suppose we start with a number *n*. We reverse the digits of
*n* and add it to *n*. If this number is a palindrome we
stop. Otherwise, we repeat the reversal and addition and continue.
For many numbers this process leads us to a palindrome!

In this task you will be given a number *n* with at most 10
digits. Your task is to carry out the process described above and
output the resulting palindrome, if you find one. However, if the
number of digits exceeds 30 and you still have not found a palindrome
then output -1.

For example if *n* is 149 then we get the following
sequence: 149, 1090, 1991. Thus your program should output 1991 in
this case. However, if we start with 196 we do not get a palindrome
before the number of digits exceeds 30 and in this case the output
should be -1.

Input format

A single line with a single integer *n*, with not more than
10 digits.

Output format

A single number that is either -1 or the palindrome generated by
the process described above.

Test data

You may assume that *n* has at most 10 digits.

Example

We now illustrate the input and output formats using the above
example.

Sample input

149

Sample output

1991