New Maths

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

"Drat!" cursed Charles.  "This stupid carry bar is not working in my Engine!  I just tried to calculate the square of a number, but it's wrong; all of the carries are lost."

"Hmm," mused Ada, "arithmetic without carries!  I wonder if I can figure out what your original input was, based on the result I see on the Engine."

Carryless addition, denoted by \oplus, is the same as normal addition, except any carries are ignored (in base 1010). Thus, 374837 \oplus 48 is 7575, not 8585.

Carryless multiplication, denoted by \otimes, is performed using the schoolboy algorithm for multiplication, column by column, but the intermediate additions are calculated using carryless addition. More formally, Let a_ma_m1a_1a_0a\_m a\_{m-1} \ldots a\_1 a\_0 be the digits of aa, where a_0a\_0 is its least significant digit. Similarly define b_nb_n1b_1b_0b\_n b\_{n-1} \ldots b\_1 b\_0 be the digits of bb. The digits of c=abc = a \otimes b are given by the following equation: \[ c_k = \left( a_0 b_k \oplus a_1 b_{k-1} \oplus \cdots \oplus a_{k-1} b_1 \oplus a_k b_0 \right) \bmod{10}, \] where any a_ia\_i or b_jb\_j is considered zero if i>mi > m or j>nj > n. For example, 91,2349 \otimes 1\\,234 is 9,8769\\,876, 901,23490 \otimes 1\\,234 is 98,76098\\,760, and 991,23499 \otimes 1\\,234 is 97,53697\\,536.

Given NN, find the smallest positive integer aa such that aa=Na \otimes a = N.

입력

The input consists of a single line with a positive integer NN, with at most 2525 digits and no leading zeros.

출력

Print, on a single line, the least positive number aa such that aa=Na \otimes a = N. If there is no such aa, print '-1' instead.