962_C. Make a Square
You are given a positive integer n, written without leading zeroes (for example, the number 04 is incorrect). 

In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros.

Determine the minimum number of operations that you need to consistently apply to the given integer n to make from it the square of some positive integer or report that it is impossible.

An integer x is the square of some positive integer if and only if x=y^2 for some positive integer y.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^{9}). The number is given without leading zeroes.

Output

If it is impossible to make the square of some positive integer from n, print -1. In the other case, print the minimal number of operations required to do it.

Examples

Input

8314


Output

2


Input

625


Output

0


Input

333


Output

-1

Note

In the first example we should delete from 8314 the digits 3 and 4. After that 8314 become equals to 81, which is the square of the integer 9.

In the second example the given 625 is the square of the integer 25, so you should not delete anything. 

In the third example it is impossible to make the square from 333, so the answer is -1.
```python
'''input
101
'''
from itertools import chain, combinations

def binarysearch(arr, x):
    l = 0
    r = len(arr) - 1
    while l <= r:
        mid = l + (r - l) // 2
        if arr[mid] == x:
            return mid
        elif arr[mid] < x:
            l = mid + 1
        else:
            r = mid - 1
    return -1

z = []

for i in range(1, 44723):
	z.append(i * i)


a = input()
s = list(a) 
k = []
for n in range(len(s)+1):
        for i in (combinations(s,n)):
            if i != ():
                ss = ''
                for j in i:
                	ss += j
                if ss[0] != '0':
                	k.append(ss)
#print(k)
k.reverse()
#print(k)
#print(b)
f = 0

for i in k:
	if binarysearch(z, int(i)) != -1:
		print(len(a) - len(i))
		f = 1
		break
if f == 0:
	print(-1)



```