New Maths
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

“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 , is the same as normal addition, except any carries are ignored (in base 10). Thus, 37⊕48 is 75, not 85.

Carryless multiplication, denoted by , is performed using the schoolboy algorithm for multiplication, column by column, but the intermediate additions are calculated using carryless addition. More formally, Let  be the digits of a, where a_0 is its least significant digit. Similarly define  be the digits of b. The digits of c=a⊗b are given by the following equation:
 mod 10,

where any a_i or b_j is considered zero if i>m or j>n. For example, 9⊗1234 is 9876987690⊗1234 is 9876098760, and 99⊗1234 is 9753697536.

Given N, find the smallest positive integer aa such that a⊗a=N.

输入描述:

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

输出描述:

Print, on a single line, the least positive number aa such that a⊗a=N. If there is no such a, print ‘-1’ instead.
示例1

输入

复制
6

输出

复制
4
示例2

输入

复制
149

输出

复制
17
示例3

输入

复制
123476544

输出

复制
11112
示例4

输入

复制
15

输出

复制
-1