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 \le n \le 2 \cdot 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.

Source: codeforces | Difficulty: MEDIUM
Tags: Mathematics

Implementation

Complete search


Solutions:
import itertools
s = input()
e = len(s)
while len(s) < 10:
	s = '0' + s
m = 0
for i in itertools.product(range(2), repeat=10):
	loc = ''
	for j in range(10):
		if i[j]:
			loc += s[j]
	if not loc:
		continue
	if loc and loc[0] == '0':
		continue
	k = int(loc) ** 0.5
	if int(k) != k:
		continue
	if len(loc) > m:
		m = len(loc)
print(e - m if m != 0 else -1)


def compare(a, b):
	last = 0
	for i in range(0, len(b), 1):
		if a.find(b[i:i + 1], last, len(a)) == -1:
			return -1
		else:
			last = a.find(b[i:i + 1], last, len(a)) + 1
	return len(a) - len(b)
string = input()
ans = []
i = 1
while int(i * i) <= int(string):
	n = compare(string, str(i * i))
	if n != -1:
		ans.append(n)
	i += 1
if len(ans) == 0:
	print(-1)
else:
	print(min(ans))


from math import *
lis = []

def func(p, i, l):
	if i == l:
		lis.append(p)
		p = p[:len(p) - 1]
		return
	func(p + s[i], i + 1, l)
	func(p, i + 1, l)

def cmp(a, b):
	if a > b:
		return 1
	return 0
s = input()
p = ''
func(p, 0, len(s))
lis = sorted(lis, key=len)
lis.reverse()
lis.remove('')
lis1 = lis[:]
lis = [i for i in lis1 if int(i) != 0]
lis1 = lis[:]
lis = []
for i in lis1:
	k = i
	p = 0
	while k[p] == '0':
		p += 1
	k = k[p:]
	lis.append(k)
lis = sorted(lis, key=len)
lis.reverse()
f = 0
for i in range(len(lis)):
	if int(sqrt(int(lis[i]))) == sqrt(int(lis[i])):
		f = 1
		break
if not f:
	print('-1')
else:
	k = lis[i]
	p = 0
	while k[p] == '0':
		p += 1
	k = k[p:]
	print(len(s) - len(k))
del lis[:]


def lcs(X, Y):
	m = len(X)
	n = len(Y)
	L = [[None] * (n + 1) for i in range(m + 1)]
	for i in range(m + 1):
		for j in range(n + 1):
			if i == 0 or j == 0:
				L[i][j] = 0
			elif X[i - 1] == Y[j - 1]:
				L[i][j] = L[i - 1][j - 1] + 1
			else:
				L[i][j] = max(L[i - 1][j], L[i][j - 1])
	return L[m][n]
x = input()
import math
ans = 0
for i in range(int(math.sqrt(int(x))), 0, -1):
	if lcs(x, str(i * i)) == len(str(i * i)):
		ans = len(str(i * i))
		break
if ans:
	print(len(x) - ans)
else:
	print(-1)


from itertools import combinations
from functools import reduce
from math import sqrt
n = input()
j = len(n)
key = -1
for _ in range(j, 0, -1):
	for i in combinations(n, _):
		ld = reduce(lambda x, y: x + y, i)
		if sqrt(int(ld)) == int(sqrt(int(ld))) and ld[0] != str(0):
			if len(n) - len(ld) < key or key == -1:
				key = len(n) - len(ld)
else:
	if key == -1:
		print(-1)
	else:
		print(key)


import sys
import math

def can_match(inp, square):
	operations = 0
	inp_idx = 0
	ok = True
	for digit in square:
		while inp_idx < len(inp) and digit != inp[inp_idx]:
			inp_idx = inp_idx + 1
			operations = operations + 1
		if inp_idx == len(inp):
			ok = False
			break
		inp_idx = inp_idx + 1
	if ok:
		return operations + (len(inp) - inp_idx - 1)
	return -1
data = sys.stdin.readlines()[0]
square = int(data)
sol = -1
while square > 0:
	square = math.floor(math.sqrt(square)) ** 2
	result = can_match(data, str(square))
	if result != -1:
		sol = result
		break
	square = square - 1
print(sol)


u = list(map(int, list(input())))
n = len(u)
d = []
for i in range(1, 100001):
	d.append(list(map(int, list(str(i * i)))))
ans = []
for k in d:
	if len(k) > n:
		break
	m = 0
	j = 0
	i = 0
	while i < n and j < len(k):
		if u[i] == k[j]:
			i += 1
			j += 1
		else:
			i += 1
			m += 1
	if j == len(k):
		ans.append(m + (n - i))
if len(ans) == 0:
	print(-1)
else:
	print(min(ans))


import math
n = int(input())
count = 0
global check
check = 10 ** 9 + 1
global cl
cl = []

def qw(n, count):
	global check
	global cl
	if n in cl or count >= check:
		return
	cl.append(n)
	if isq(n):
		if count < check:
			check = count
			return
	else:
		count += 1
		s = str(n)
		if len(s) == 1:
			return
		for x in range(len(s)):
			if x == 0:
				if s[1] != '0':
					qw(int(s[:x] + s[x + 1:]), count)
			else:
				qw(int(s[:x] + s[x + 1:]), count)

def isq(n):
	if int(math.sqrt(n)) ** 2 == n:
		return True
	else:
		return False
qw(n, count)
if check == 10 ** 9 + 1:
	print(-1)
else:
	print(check)


def substring(a, b):
	(i, j) = (0, 0)
	while i < len(a) and j < len(b):
		if a[i] == b[j]:
			i += 1
		j += 1
	return i == len(a)
n = input()
k = 1
best_len = 0
while len(str(k * k)) <= len(n):
	tmp = str(k * k)
	if substring(tmp, n):
		best_len = max([best_len, len(tmp)])
	k += 1
if best_len == 0:
	print(-1)
else:
	print(len(n) - best_len)


import math
s = input().strip()
mn = []
for m in range(1 << len(s)):
	make = []
	for i in range(len(s)):
		if m & 1 << i:
			make += [s[i]]
	x = ''.join(make)
	if len(x) == 0:
		x = '0'
		continue
	cum = int(x)
	if cum == 0:
		continue
	if math.ceil(math.sqrt(cum)) == math.floor(math.sqrt(cum)):
		mn += [''.join(make)]
for (i, val) in enumerate(mn):
	if len(val) == 0:
		val = '0'
		continue
	mn[i] = str(int(val))
mn.sort(key=lambda x: len(x))
print(len(s) - len(mn[-1]) if len(mn) else -1)


from itertools import combinations as cmb
sqset = {i * i for i in range(1, 45000)}

def f(t):
	s = ''
	for c in t:
		s += c
	return s
s = input()
ans = -1
for j in range(len(s), 0, -1):
	l = list(cmb(s, j))
	for tup in l:
		if tup[0] != '0' and int(f(tup)) in sqset:
			ans = len(s) - j
			break
	if ans != -1:
		break
print(ans)


def isSquare(n):
	return int(n ** 0.5) == n ** 0.5

def removeDigits(number, digits, digitCounter):
	indices = {}
	for i in range(digitCounter):
		if not 1 << i & digits == 0:
			indices[i] = 1
	answer = ''
	for i in range(digitCounter):
		if not digitCounter - i - 1 in indices:
			answer += str(number)[i]
	if answer[0] == '0':
		return 2
	elif answer == '':
		return 0
	else:
		return int(answer)
number = int(input())
min = 1 << 30
digitCount = len(str(number))
for i in range((1 << digitCount) - 1):
	digitCounter = 0
	breaknow = False
	for j in range(digitCount):
		if not i & 1 << j == 0:
			digitCounter += 1
	if breaknow:
		continue
	if isSquare(removeDigits(number, i, digitCount)):
		if digitCounter < min:
			min = digitCounter
if min == 1 << 30:
	print(-1)
else:
	print(min)


from math import sqrt
from itertools import combinations
n = input()

def perm(c, d):
	a = []
	for p in list(combinations(c, d)):
		if set(p) not in a:
			a.append(set(map(int, p)))
	return a
if sqrt(int(n)) % 1 == 0:
	print(0)
	exit()
for check in range(1, len(n)):
	to_per = '0123456789'
	for j in perm(to_per[:len(n)], check):
		n1 = ''
		for o in range(len(n)):
			if o not in j:
				n1 += n[o]
		if sqrt(int(n1)) % 1 == 0 and int(n1) != 0 and (n1[0] != '0'):
			print(check)
			exit()
print(-1)


def check(s, it):
	pos = 0
	cur = len(it)
	for i in range(len(s)):
		if pos == cur:
			break
		if s[i] == it[pos]:
			pos += 1
	return pos == cur
n = int(input())
s = str(n)
a = []
ans = 10 ** 20
for i in range(1, n + 1):
	if i * i > n:
		break
	else:
		it = str(i * i)
		if check(s, it):
			ans = min(ans, len(s) - len(it))
print(-1) if ans == 10 ** 20 else print(ans)


s = input()
for i in range(10 ** 5, 0, -1):
	(t, p) = (str(i * i) + '$', 0)
	for x in s:
		if x == t[p]:
			p += 1
	if p == len(t) - 1:
		print(len(s) - len(t) + 1)
		break
else:
	print(-1)


import sys
import math

def I():
	return int(sys.stdin.readline())

def is_square(n):
	i = int(math.sqrt(n))
	if n == i * i:
		return True
	else:
		return False

def solve(n):
	_set = {n}
	cnt = 0
	while len(_set) > 0:
		_new_set = set()
		for _ in range(len(_set)):
			i = _set.pop()
			if is_square(i):
				return cnt
			splitInt = list(str(i))
			if len(splitInt) == 1:
				continue
			for j in range(len(splitInt)):
				if j == 0 and splitInt[1] == '0':
					continue
				_new_set.add(int(''.join(splitInt[:j] + splitInt[j + 1:])))
		_set = _new_set
		_new_set = set()
		cnt += 1
	return -1

def main():
	print(solve(I()))
main()


import math

def isPerfectSquare(x):
	sr = math.sqrt(x)
	return sr - math.floor(sr) == 0

def s(arr, n):
	c = []
	opsize = math.pow(2, n)
	for counter in range(1, int(opsize)):
		l = []
		for j in range(0, n):
			if counter & 1 << j:
				l.append(arr[j])
		c.append(l)
	return c
k = list(input())
z = k
k = s(k, len(k))
k = sorted(k)
k.reverse()
for i in range(len(k)):
	k[i] = str(''.join(k[i]))
for i in range(len(k)):
	if isPerfectSquare(int(k[i])) and k[i][0] != '0':
		k[i] = [len(z) - len(k[i]), 1]
	else:
		k[i] = 0
l = 10000000000000000
for i in range(len(k)):
	try:
		if k[i][1] == 1:
			if l > k[i][0]:
				l = k[i][0]
	except:
		pass
if l == 10000000000000000:
	print(-1)
else:
	print(l)


def f(n):
	n = int(n)
	return (n ** 0.5 // 1) ** 2 == n

def g(n):
	max_len = 0
	last_cell = [0 for i in range(len(n))]
	cell1 = [1 for i in range(len(n))]
	cell = ''
	for i in range(2 ** 10):
		if last_cell == cell:
			break
		for j in range(len(n)):
			if last_cell[j] == 0:
				for h in range(j - 1, -1, -1):
					last_cell[h] = 0
				last_cell[j] = 1
				break
		for j in range(len(n)):
			if last_cell[j] == 1:
				cell += n[j]
		if f(cell) and len(cell) > max_len and (cell[0] != '0'):
			max_len = len(cell)
		cell = ''
	return len(n) - max_len
n = list(input())
cell = g(n)
if cell == len(n):
	print(-1)
else:
	print(cell)


s = input()
a = ['0', '1']
i = 0
l = len(s)
while i < l - 1:
	b = []
	for j in a:
		b.append('0' + j)
	for j in a:
		b.append('1' + j)
	a = b
	i += 1
import math
q = 0
r = 10 ** 18
a = a[1:]
for i in a:
	k = ''
	for j in range(l):
		if i[j] == '1':
			k += s[j]
	z = 0
	x = len(k)
	while z < x:
		if k[z] == '0':
			z += 1
		else:
			break
	k = k[z:]
	if k == '':
		continue
	p = int(k)
	if p != 0:
		if math.ceil(p ** 0.5) == math.floor(p ** 0.5):
			q += 1
			r = min(r, i.count('0') + z)
if q == 0:
	print(-1)
else:
	print(r)


import math

def nop(a, b):
	l = 0
	for i in range(len(a)):
		d = a[i]
		while l < len(b) and b[l] != d:
			l += 1
		if l >= len(b) and b[l - 1] != d:
			return 0
		elif l < len(b) and b[l] != d:
			return 0
		l += 1
		if i < len(a) - 1 and l >= len(b):
			return 0
	return 1
a = int(input())
b = int(math.sqrt(a))
c = []
k = b
for i in range(k):
	if nop(str(b ** 2), str(a)) == 1:
		c.append(len(str(a)) - len(str(b ** 2)))
	b -= 1
c.sort()
if len(c) > 0:
	print(c[0])
else:
	print(-1)


import itertools as it
import functools as fu
import math
leftover = []

def nint(n=1):
	global leftover
	while len(leftover) < n:
		leftover.extend(input().split())
	res = tuple(map(int, leftover[:n]))
	leftover = leftover[n:]
	return res if len(res) > 1 else res[0]

def nlin():
	global leftover
	if not leftover:
		return input()
	return ' '.join(leftover)

def ntok():
	global leftover
	if not leftover:
		leftover.extend(input().split())
	return leftover[0]
s = input()
n = int(s)
mind = 999
for i in range(1, int(math.sqrt(n)) + 1):
	s2 = str(i * i)
	d = 0
	p = 0
	i = -1
	for c in s:
		i += 1
		if c == s2[p]:
			p += 1
			if p == len(s2):
				d += len(s) - i - 1
				mind = min(mind, d)
				break
		else:
			d += 1
if mind == 999:
	mind = -1
print(mind)


def test(sp1, sp2):
	i = 0
	j = 0
	while len(sp1) != i and len(sp2) != j:
		if sp1[i] == sp2[j]:
			i += 1
			j += 1
		else:
			i += 1
	return j == len(sp2)
z = input()
sp1 = list(z)
z = int(z)
p = False
ans = -1
for i in range(1, 44721):
	sp2 = list(str(i * i))
	if z == i ** 2:
		p = True
	if test(sp1, sp2):
		ans = len(sp1) - len(sp2)
if z == 1999967841:
	print(0)
elif p:
	print(0)
else:
	print(ans)


import math

def isperfect(x):
	sr = math.sqrt(x)
	return sr - math.floor(sr) == 0
s = input()
arr = []
for i in range(1 << len(s)):
	xx = ''
	for j in range(len(s)):
		if i & 1 << j > 0:
			xx += s[j]
	if len(xx) > 0 and xx[0] == '0':
		continue
	elif len(xx) > 0:
		arr.append([int(xx), len(xx)])
arr = sorted(arr, key=lambda item: item[1], reverse=True)
for i in range(len(arr)):
	if isperfect(arr[i][0]):
		tt = arr[i][1]
		print(abs(tt - len(s)))
		exit()
print(-1)


from math import sqrt
a = input()
n = int(a)
for i in (str(i * i) for i in range(int(sqrt(n)) + 1, 0, -1)):
	a_index = 0
	find_part = None
	for c in i:
		index = a.find(c, a_index)
		if index == -1:
			break
		else:
			a_index = index + 1
	else:
		print(len(a) - len(i))
		exit()
print(-1)


import sys
import math
import bisect

def is_subsequence(s, t):
	n = len(s)
	m = len(t)
	j = 0
	for i in range(n):
		if s[i] == t[j]:
			j += 1
			if j == m:
				return True
	return False

def solve(n):
	min_val = 10 ** 18
	for i in range(1, math.floor(math.sqrt(n)) + 1):
		if is_subsequence(str(n), str(i ** 2)):
			val = len(str(n)) - len(str(i ** 2))
			min_val = min(min_val, val)
	if min_val == 10 ** 18:
		return -1
	return min_val

def main():
	n = int(input())
	ans = solve(n)
	print(ans)
main()


import math as ma
from sys import exit

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())
import math

def perfectSquare(s):
	n = len(s)
	ans = -1
	num = ''
	for i in range(1, 1 << n):
		str = ''
		for j in range(0, n):
			if i >> j & 1:
				str = str + s[j]
		if str[0] != '0':
			temp = 0
			for j in range(0, len(str)):
				temp = temp * 10 + (ord(str[j]) - ord('0'))
			k = int(math.sqrt(temp))
			if k * k == temp:
				if ans < len(str):
					ans = len(str)
					num = str
	if ans == -1:
		return ans
	else:
		return n - ans
print(perfectSquare(input()))


import math
from itertools import chain, combinations

def powerset(seq):
	if len(seq) <= 1:
		yield seq
		yield []
	else:
		for item in powerset(seq[1:]):
			yield ([seq[0]] + item)
			yield item
n = list(input())
orign = n

def valid(subset):
	m = ''.join(subset)
	if len(m) == 0:
		return False
	if subset[0] == '0':
		return False
	if math.sqrt(int(m)) == int(math.sqrt(int(m))):
		return True
	return False
res = []
subsets = list(powerset(n))
for i in subsets:
	if valid(i):
		res.append(len(n) - len(i))
if len(res) == 0:
	print(-1)
else:
	print(min(res))


import math
import functools
n = int(input())

def is_square(n):
	return int(math.sqrt(n)) ** 2 == n

def remove_digit(digits, i):
	res = 0
	for (j, d) in enumerate(digits):
		if j == i:
			continue
		res = 10 * res + d
	return res

@functools.lru_cache(maxsize=None)
def f(n):
	if is_square(n):
		res = 0
	else:
		digits = [int(c) for c in str(n)]
		if len(digits) == 1:
			res = float('inf')
		else:
			if digits[1] == 0:
				start = 1
			else:
				start = 0
			succ = [remove_digit(digits, i) for i in range(start, len(digits))]
			res = min((f(s) + 1 for s in succ), default=float('inf'))
	return res
res = f(n)
if res == float('inf'):
	print(-1)
else:
	print(res)


n = input()
s = int(int(n) ** 0.5)
while s:
	r = str(s * s)
	c = 0
	for i in range(len(n)):
		if n[i] == r[c]:
			c += 1
			if c == len(r):
				exit(print(len(n) - c))
	s -= 1
print(-1)


n = input()
tb = 44721
while tb > 0:
	ans = str(tb * tb)
	j = 0
	for i in range(len(n)):
		if n[i] == ans[j]:
			j += 1
			if j == len(ans):
				break
	if j == len(ans):
		break
	tb -= 1
if tb > 0:
	print(len(n) - len(ans))
else:
	print(-1)


def check(t, s):
	cur_t = 0
	for j in range(len(s)):
		while cur_t < len(t) and t[cur_t] != s[j]:
			cur_t += 1
		if cur_t == len(t):
			return False
		cur_t += 1
	return True
s1 = input()
for i in range(45 * 1000, 0, -1):
	s2 = str(i * i)
	if check(s1, s2):
		print(len(s1) - len(s2))
		exit(0)
print(-1)


import math, itertools
n = int(input())
d = {}
for i in range(1, 44722):
	a = i * i
	d.update({a: i})
s = str(n)
temp = []
for i in range(1, len(s)):
	c = list(itertools.combinations(s, i))
	temp.append(c)
combinations = []
for i in temp:
	for j in i:
		if len(j) > 1:
			x = ''
			for k in j:
				x = x + list(k)[0]
			combinations.append(x)
		else:
			t = list(j)
			combinations.append(t[0])
combinations.append(s)
minarray = []
for i in range(len(combinations) - 1, -1, -1):
	try:
		if combinations[i].startswith('0'):
			continue
		x = int(combinations[i])
		y = d[x]
		if y > 0:
			minarray.append(len(s) - len(combinations[i]))
	except:
		pass
if len(minarray) > 0:
	print(min(minarray))
else:
	print(-1)


import math

def check(num):
	st = int(math.sqrt(num))
	if st * st == num:
		return True
	return False
n = input()
l = len(n)
t = 1 << l
ans = 999
for i in range(1, t):
	str = ''
	re = 0
	for j in range(l):
		if 1 << j & i != 0:
			str += n[j]
		else:
			re += 1
	if str[0] != '0' and check(int(str)):
		ans = min(ans, re)
if ans == 999:
	ans = -1
print(ans)


import math

def isSquarePerfect(n):
	squareRoot = math.sqrt(n)
	squareRoot = round(squareRoot)
	return squareRoot * squareRoot == n
n = input()
ans = 11
found = False
numbers = []
for (index, digit) in enumerate(n):
	for i in range(len(numbers)):
		numbers.append([numbers[i][0] + digit, numbers[i][1] + [index]])
	if digit != '0':
		numbers.append([digit, [index]])
for number in numbers:
	if isSquarePerfect(int(number[0])):
		found = True
		total = len(n) - len(number[0])
		ans = min(ans, total)
if not found:
	print(-1)
else:
	print(ans)


from math import sqrt
n = input()
ans = 100
for m in range(1, 1 << len(n)):
	cur = ''
	for i in range(len(n)):
		if m >> i & 1:
			cur += n[i]
	if cur[0] == '0':
		continue
	v = int(cur)
	s = int(sqrt(v))
	if s * s == v or (s + 1) * (s + 1) == v:
		ans = min(ans, len(n) - len(cur))
print(ans if ans < 100 else -1)


n = input()
x = 1
a = []
while x * x <= 2 * 10 ** 9:
	a.append(str(x * x))
	x += 1
ans = 100
for s in a:
	(i, j) = (0, 0)
	if len(s) > len(n):
		break
	while i < len(n) and j < len(s):
		if n[i] == s[j]:
			j += 1
		i += 1
	if j == len(s):
		ans = min(ans, len(n) - len(s))
if ans == 100:
	print(-1)
else:
	print(ans)


import math
n = list(list(input()))
m = len(n)
ans = m
for i in range(1, 2 ** m):
	k = int(''.join([n[j] for j in range(m) if i >> j & 1 == 1]))
	if 0 < k and round(math.sqrt(k)) ** 2 == k:
		ans = min(ans, m - len(str(k)))
if ans == m:
	print(-1)
else:
	print(ans)


from math import *
(a, ans, x) = (input(), -1, [])
for i in a:
	y = x[:]
	for t in y:
		m = t * 10 + int(i)
		if ceil(m ** 0.5) == int(m ** 0.5):
			if ans < m:
				ans = m
		x.append(m)
	if i != '0':
		i = int(i)
		if ceil(i ** 0.5) == int(i ** 0.5):
			if ans < i:
				ans = i
		x.append(int(i))
print(ans if ans == -1 else len(a) - len(str(ans)))


import itertools as it
import math as m

def check(x):
	if x < 10:
		return x in (1, 4, 9)
	r = m.sqrt(x)
	r = int(r)
	if r * r == x or (r + 1) * (r + 1) == x:
		return True
	return False

def run():
	n = input()
	q = [n]
	cnt = 0
	while len(q):
		q2 = []
		for x in q:
			if check(int(x)):
				print(cnt)
				return
			if len(x) == 1:
				continue
			for i in range(len(x)):
				if i != 0 or x[1] != '0':
					q2.append(x[:i] + x[i + 1:])
		cnt += 1
		q = q2
	print(-1)
run()


from math import *
inp = int(input())
li = []
while inp > 0:
	li.append(inp % 10)
	inp //= 10
li.reverse()
res = len(li)
for i in range(1, 2 ** len(li)):
	cur = 0
	li_num = []
	for j in range(len(li)):
		if i & 1 << j:
			li_num.append(str(li[j]))
			cur += 1
		if len(li_num) > 0:
			num = int(''.join(li_num))
		else:
			num = 0
	if sqrt(num) == int(sqrt(num)) and li_num[0] != '0':
		res = min(len(li) - cur, res)
if res == len(li):
	print('-1')
else:
	print(res)


from sys import stdin, stdout
n = stdin.readline().strip()
s = int(int(n) ** 0.5)
while s:
	r = str(s * s)
	c = 0
	for i in range(len(n)):
		if n[i] == r[c]:
			c += 1
			if c == len(r):
				exit(print(len(n) - c))
	s -= 1
print(-1)


def solve():
	n = int(input())
	squares = set()
	j = 1
	while j * j <= 2 * 10 ** 9:
		squares.add(j * j)
		j += 1
	m = float('inf')
	for i in range(1, 2 ** len(str(n))):
		b = bin(i)[2:]
		x = '0' * (len(str(n)) - len(b)) + b
		z = ''.join([str(n)[i] for i in range(len(str(n))) if int(x[i])])
		if int(z) in squares and (len(z) == 1 or z[0] != '0'):
			m = min(m, x.count('0'))
	if m == float('inf'):
		return -1
	else:
		return m
print(solve())


from collections import deque
import math
s = deque([(input(), 0)])
created = set()
visited = set()
while len(s):
	(x, l) = s.popleft()
	visited.add(x)
	if not len(x):
		print(-1)
		break
	y = math.trunc(math.sqrt(int(x))) ** 2
	if y == int(x) and (not x.startswith('0')):
		print(l)
		break
	for i in range(len(x)):
		z = ''.join(x[:i] + x[i + 1:])
		if not z in visited and (not (z, l + 1) in created):
			created.add((z, l + 1))
			s.append((z, l + 1))


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
a = z()
x = []
ans = -1
for i in a:
	y = x.copy()
	for t in y:
		x.append(t * 10 + int(i))
	if i != '0':
		x.append(int(i))
for i in x:
	if int(i ** 0.5) == ceil(i ** 0.5):
		if ans < i:
			ans = i
if ans == -1:
	print(ans)
	exit()
print(len(a) - len(str(ans)))


def Slove():
	n = input()
	sq = int(int(n) ** 0.5)
	while sq:
		tmp = str(sq * sq)
		idx = 0
		for i in n:
			if i == tmp[idx]:
				idx = idx + 1
				if idx == len(tmp):
					return len(n) - idx
		sq -= 1
	return -1
print(Slove())


from math import sqrt
cache = {}

def calc(s, c=0):
	if len(s) == 0:
		return None
	if s[0] == '0':
		return None
	if s in cache:
		return cache[s] + c
	i = int(s)
	v = sqrt(i)
	if v == int(v):
		return c
	results = []
	for i in range(len(s)):
		if i == 0 and s[i] == '0':
			continue
		results.append(calc(s[:i] + s[i + 1:]))
	results = [result for result in results if result is not None]
	if len(results) == 0:
		return None
	cache[s] = min(results) + 1
	return min(results) + 1
s = input()
r = calc(s)
if r is not None:
	print(r)
else:
	print(-1)


from math import sqrt
ns = input()
n = int(ns)
ans = len(ns) + 1
for i in range(1, 2 ** len(ns)):
	(num, cnt) = (0, len(ns))
	for j in range(len(ns)):
		if i & 2 ** j != 0:
			num = num * 10 + int(ns[j])
			cnt -= 1
	sq = int(sqrt(num))
	if sq * sq == num and num > 0 and (len(str(num)) + cnt == len(ns)):
		ans = min(ans, cnt)
print(ans if ans <= len(ns) else -1)


n = input()
ma = int(int(n) ** 0.5)
while ma > 0:
	ans = str(ma ** 2)
	j = 0
	for i in range(len(n)):
		if n[i] == ans[j]:
			j += 1
			if j == len(ans):
				print(len(n) - j)
				exit()
	ma -= 1
print('-1')


def check(a, b):
	k = 0
	asize = len(a)
	for j in range(asize):
		if a[j] == b[k]:
			k += 1
		if k == len(b):
			break
	if k == len(b):
		return asize - len(b)
	return -1
s = input()
for i in range(45000, 0, -1):
	d = check(s, str(i * i))
	if d != -1:
		print(d)
		exit()
print(-1)


import sys
square = set()
for i in range(1, 44722):
	square.add(str(i * i))
s = input()
n = len(s)
inf = 100
ans = inf
for bit in range(1, 1 << n):
	w = ''.join((s[i] for i in range(n) if 1 << i & bit))
	if w in square:
		ans = min(ans, n - bin(bit).count('1'))
print(ans if ans != inf else -1)


l = int(input())
l1 = str(l)
w = 1
ma = -1
while w * w <= l:
	s = str(w * w)
	i = 0
	k = 0
	for x in s:
		for j in range(i, len(l1)):
			if x == l1[j]:
				k += 1
				break
		i = j + 1
	if k == len(s):
		ma = len(l1) - len(s)
	w += 1
print(ma)


from math import sqrt
import itertools

def issq(k):
	k = int(k)
	return k == int(sqrt(k)) ** 2
ns = input().strip()
l = len(ns)

def getsub(ns, it):
	return ''.join((ns[i] for i in it))

def findmin(ns):
	for i in range(l, 0, -1):
		for it in itertools.combinations(list(range(l)), i):
			its = getsub(ns, it)
			if its.startswith('0'):
				continue
			if issq(its):
				return l - i
	return -1
print(findmin(ns))


n = int(input())
s = str(n)
x = int(n ** 0.5)
b = 0
while True:
	k = str(x * x)
	q = 0
	b = 0
	for i in k:
		if i not in s[q:]:
			b = 1
			break
		else:
			q = q + s[q:].find(i) + 1
	if b == 0:
		print(len(s) - len(k))
		b = 2
		break
	x -= 1
	if x < 1:
		break
if b < 2:
	print(-1)


s = input()
a = list()
for i in range(1, 100000):
	a.append(str(i * i))
sz = len(s)
mn = 100000000000
for i in range(len(a)):
	k = 0
	if len(a[i]) > sz:
		break
	for j in range(sz):
		if s[j] == a[i][k]:
			k += 1
		if k == len(a[i]):
			mn = min(mn, sz - k)
			break
if mn == 100000000000:
	print(-1)
else:
	print(mn)


n = input()
count = len(n)
n = (10 - len(n)) * '0' + n
min1 = 10
for i in range(1, 2 ** 10):
	b = bin(i)
	b = b[2:]
	b = (10 - len(b)) * '0' + b
	s = ''
	for i in range(10):
		if b[i] == '1':
			s += n[i]
	if len(s) > 0 and s[0] == '0':
		continue
	s = int(s)
	if int(s ** 0.5) ** 2 == s:
		min1 = min(b[len(b) - count:].count('0'), min1)
if min1 == 10:
	print(-1)
else:
	print(min1)


from itertools import combinations
from math import sqrt
(s, ans) = (input(), -1)
for i in range(len(s), 0, -1):
	for a in combinations(s, i):
		if a[0] != '0':
			n = int(''.join(a))
			s1 = sqrt(n)
			if int(s1) == s1:
				ans = len(s) - i
				break
	if ans != -1:
		break
print(ans)


from math import sqrt, floor
n = int(input())
n_list = list(str(n))
proverka = []
for i in ['0', '1', '4', '9', '6', '5']:
	proverka.append(n_list.count(i))
if proverka.count(0) == 6:
	ans = -1
else:
	i_list = []
	ans = -1
	for i in range(floor(sqrt(n)), 0, -1):
		trig = True
		sovpadenie = 0
		position = 0
		i_list.clear()
		i_list = list(str(i * i))
		for k in range(len(i_list)):
			for s in range(position, len(n_list)):
				if n_list[s] == i_list[k]:
					position = s + 1
					sovpadenie += 1
					break
				elif s == len(n_list) - 1:
					trig = False
			if trig:
				if sovpadenie == len(i_list):
					ans = len(n_list) - len(i_list)
					break
				else:
					continue
			else:
				break
		if ans != -1:
			break
print(ans)


n = input()
l1 = []
for i in range(1, 50001):
	l1.append(i * i)

def check(k, n):
	l2 = len(k)
	i = 0
	for u in n:
		if u == k[i]:
			i = i + 1
		if i == l2:
			return True
			break
	return False
g = 1
for j in range(49999, -1, -1):
	k = str(l1[j])
	if check(k, n):
		print(len(n) - len(k))
		g = 0
		break
if g:
	print(-1)


import sys
from itertools import combinations
input = sys.stdin.readline
n = int(input())
s = list(str(n))
x = len(s)
l = []
for i in range(len(s)):
	l.append(i)
ans = 10000
for i in range(1, x + 1):
	for j in combinations(l, i):
		u = []
		for k in j:
			u.append(s[k])
		p = ''.join(u)
		if p[0] == '0':
			continue
		m = int(p)
		m = m ** 0.5
		h = int(m)
		if h == m:
			w = x - i
			if w < ans:
				ans = w
if ans == 10000:
	ans = -1
print(ans)


def is_square(n):
	return round(n ** 0.5) ** 2 == n
bestcur = []
cur = []

def do(n, i):
	global cur, bestcur
	if cur and cur[0] == '0':
		return
	if i < len(n):
		cur.append(n[i])
		if cur[0] == '0':
			cur.pop()
		else:
			if cur and is_square(int(''.join(cur))) and (len(bestcur) < len(cur)):
				bestcur = cur[:]
			do(n, i + 1)
			cur.pop()
		do(n, i + 1)
n = input()
do(n, 0)
if not bestcur:
	print(-1)
else:
	print(len(str(n)) - len(bestcur))


import sys
from math import *
readints = lambda : map(int, input().strip('\n').split())
n = input()
squares = []
x = 1
while True:
	if x * x > 2 * 10 ** 9:
		break
	squares.append(str(x * x))
	x += 1
inf = 2 * 10 ** 9 + 5
ans = inf

def edits(cur, tobe):
	i = 0
	cnt = 0
	for c in tobe:
		j = cur.find(c, i)
		if j == -1:
			return -1
		cnt += j - i
		i = j + 1
	cnt += len(cur) - i
	return cnt
for sq in squares:
	e = edits(n, sq)
	if e != -1:
		ans = min(ans, e)
if ans == inf:
	ans = -1
print(ans)


import itertools
n = input()
li = list(n)
all_sq = [x ** 2 for x in range(44723)]
if int(n) in all_sq:
	print(0)
else:
	digitlist = [x for x in range(len(li) - 1, -1, -1)]
	for (idx, val) in enumerate(li):
		for comb in list(itertools.combinations(digitlist, idx)):
			templist = li.copy()
			for rm_digit in comb:
				templist.pop(rm_digit)
			if templist[0] != '0':
				if int(''.join(templist)) in all_sq:
					print(idx)
					exit()
	print(-1)


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = insr()
ans = 1000000000

def root(n):
	hi = n
	lo = 0
	ans = 0
	while hi >= lo:
		mid = (hi + lo) // 2
		if mid * mid <= n:
			ans = mid
			lo = mid + 1
		else:
			hi = mid - 1
	return ans

def perfect(n):
	return root(n) * root(n) == n and n > 0
for i in range(1, 1 << len(x)):
	n = 0
	cnt = 0
	for j in range(len(x)):
		if i & 1 << j:
			n *= 10
			n += int(x[j])
		else:
			cnt += 1
	if perfect(n) and len(str(n)) + cnt == len(x):
		ans = min(ans, cnt)
if ans == 1000000000:
	print(-1)
else:
	print(ans)


import math
from collections import deque

def f(n):
	y = []
	for i in range(len(n)):
		w = n[0:i] + n[i + 1:]
		if w != '' and w[0] == '0':
			continue
		y.append(w)
	return y
n = input()
p = len(n)
y = None
v = set()
q = deque([n])
while q:
	n = q.popleft()
	if n == '':
		y = -1
		break
	if n in v:
		continue
	v.add(n)
	s = math.sqrt(int(n))
	if int(s) != s:
		q.extend(f(n))
	else:
		y = p - len(n)
		break
print(y)


from math import sqrt, floor

def solve(var):
	sq = floor(sqrt(var))
	if sq * sq == var:
		return True
	else:
		return False

def stn(a):
	l = len(a) - 1
	num = 0
	for i in range(0, l + 1):
		num = num + pow(10, l - i) * int(a[i])
	return num
s = input()
n = len(s)
ans = 10 ** 18
for i in range(1 << n):
	a = ''
	for j in range(n):
		if i & 1 << j:
			a += s[j]
	if len(a) == 0:
		continue
	if a[0] == '0':
		continue
	aa = stn(a)
	flag = solve(aa)
	op = len(s) - len(a)
	if flag == True:
		ans = min(ans, op)
if ans == 10 ** 18:
	print('-1')
else:
	print(ans)


n = int(input())
i = 1
l = []
while i * i <= n:
	l.append(str(i * i))
	i += 1
l = l[::-1]
cnt = 0
flag = 0
for i in l:
	s = str(n)
	cnt = 0
	for j in i:
		for k in range(len(s)):
			if s[k] == j:
				cnt += 1
				s = s[k + 1:]
				break
	if cnt == len(i):
		flag = 1
		break
if flag:
	print(len(str(n)) - cnt)
else:
	print(-1)


import math
import queue
from itertools import permutations

def is_square(l):
	x = math.floor(math.sqrt(l))
	if x * x == l or (x - 1) * (x - 1) == l or (x + 1) * (x + 1) == l:
		return True
	else:
		return False
max_len = -1
s = input()
n = len(s)

def cal(t, k):
	global max_len
	if k >= n:
		if len(t) > 0 and t[0] != '0' and is_square(int(t)):
			max_len = max(max_len, len(t))
		return
	else:
		cal(t, k + 1)
		cal(t + s[k], k + 1)
cal('', 0)
if max_len == -1:
	print(-1)
else:
	print(n - max_len)


s = input()
L = len(s)
r = 0

def check(s, b, l):
	t = 0
	for i in range(l):
		ok = 0
		for j in range(t, L):
			if b[i] == s[j]:
				t = j + 1
				ok = 1
				break
		if not ok:
			return 0
	return 1
for i in range(1, int(int(s) ** 0.5) + 2):
	b = str(i * i)
	l = len(b)
	if check(s, b, l):
		r = max(l, r)
print(L - r if r else -1)


import math
ans = ['']

def solve(pos: int):
	global n
	sz = len(ans)
	for i in range(sz):
		if ans[i] != '' or n[pos] != '0':
			ans.append(ans[i] + n[pos])
	if pos < len(n) - 1:
		solve(pos + 1)
n = input()
if int(math.sqrt(int(n))) ** 2 == int(n):
	print(0)
	exit()
solve(0)
ans.sort(key=lambda x: len(x), reverse=True)
for i in ans:
	if i != '' and int(math.sqrt(int(i))) ** 2 == int(i):
		print(len(n) - len(i))
		exit()
print(-1)


import sys
import math
while True:
	try:

		def solution(n):
			num = [0] * 16
			mx = maxi = 0
			ln = len(n)
			if math.ceil(math.sqrt(int(n))) == math.floor(math.sqrt(int(n))):
				print(0)
				return
			while num[0] == 0:
				num[len(n)] += 1
				for i in range(ln, 0, -1):
					if num[i] == 2:
						num[i - 1] += 1
						num[i] = 0
				has = ans = 0
				for i in range(1, ln + 1, 1):
					if num[i] == 1 and n[i - 1] == '0' and (has == 0):
						break
					elif num[i] == 1:
						has += 1
						ans = ans * 10 + int(n[i - 1])
				if math.ceil(math.sqrt(ans)) == math.floor(math.sqrt(ans)) and ans > 0:
					if mx < ans:
						mx = ans
						maxi = has
			if mx > 0:
				print(ln - maxi)
			else:
				print('-1')

		def read():
			n = input()
			solution(n)
		if __name__ == '__main__':
			read()
	except EOFError:
		break


import math
n = input()
cm = float('inf')
for i in range(1, math.ceil((10 ** 9 * 2) ** 0.5) + 1):
	b = []
	start = -1
	for j in str(i ** 2):
		try:
			start = n.index(j, start + 1)
			b.append(start)
		except ValueError:
			break
	else:
		d = len(n) - len(b)
		cm = min(cm, d)
print(-1 if cm == float('inf') else cm)


from math import *

def mini(n, i, s):
	if i == len(n):
		while s[0:1] == '0':
			s = s[1:]
		if s == '':
			return 500
		p = int(sqrt(int(s)))
		if p * p == int(s):
			return len(n) - len(s)
		else:
			return 500
	t = s + n[i:i + 1]
	return min(mini(n, i + 1, s), mini(n, i + 1, t))
n = input()
s = ''
x = mini(n, 0, s)
if x == 500:
	print(-1)
else:
	print(x)


n = int(input())
d = []
i = 1
ns = str(n)
while i * i <= n:
	d.append(i * i)
	i += 1
for j in d[::-1]:
	if j == n:
		print(0)
		exit()
	else:
		c = 0
		for k in range(len(ns)):
			if ns[k] == str(j)[c]:
				c += 1
			if c == len(str(j)):
				print(len(ns) - c)
				exit()
print(-1)


import math

def ok(n):
	k = int(n)
	return k == int(math.sqrt(k)) ** 2
s = input()
mx = -1
for i in range(0, 1 << len(s)):
	tmp = ''
	for j in range(0, len(s)):
		if i & 1 << j:
			tmp = tmp + s[j]
	if len(tmp) > 0 and tmp[0] != '0' and (ok(tmp) == True):
		mx = max(mx, len(tmp))
if mx == -1:
	print(-1)
else:
	print(len(s) - mx)


mn = 10 ** 10

def solve(n, a):
	if len(n) == 0:
		return 10 ** 10
	if n[0] == '0':
		return 10 ** 10
	global mn
	if int(n) in ans:
		return a
	else:
		for i in range(len(n)):
			m = list(n)
			m.pop(i)
			if len(m) > 0:
				m = ''.join(m)
			else:
				continue
			s = solve(m, a + 1)
			mn = min(s, mn)
		return mn
for _ in range(1):
	i = 1
	ans = set()
	while i * i <= 2 * 10 ** 9:
		ans.add(i * i)
		i += 1
	n = input()
	x = solve(n, 0)
	if x == 10 ** 10:
		print(-1)
		continue
	print(x)


from itertools import combinations
from math import floor, sqrt

def fn(x):
	n = len(x)
	ops = -1
	for i in reversed(range(1, n + 1)):
		for y in filter(lambda o: o[0] != '0', combinations(x, i)):
			y = int(''.join(y))
			if floor(sqrt(y)) ** 2 == y:
				ops = i
				return n - ops
	return ops
print(fn(list(input())))


nm = input()
if (nm == '1') | (nm == '0'):
	print(0)
	raise SystemExit
a = []
pos = 0
for i in range(44722):
	a.append(i * i)
i = 1
max = 0
for i in range(44721, 1, -1):
	if len(str(a[i])) != len(str(nm)):
		i = i * 10
	else:
		pos = i
		pn = a[i]
		break
flag1 = False
flag2 = False
for i in range(pos, 0, -1):
	spn = str(a[i])
	snm = str(nm)
	if snm == '1':
		print(len(snm) - len(spn))
		exit()
	for j in range(len(spn)):
		for k in range(len(snm)):
			if len(snm) - k >= len(spn) - j:
				if spn[j] == snm[k]:
					if j + 1 == len(spn):
						print(len(snm) - len(spn))
						exit()
					j = j + 1
					continue
				else:
					if k + 1 == len(snm):
						flag1 = True
					continue
			else:
				flag1 = True
				break
		if flag1 == True:
			break
	if flag1 == True:
		flag1 = False
		continue
	print(len(snm) - len(spn))
	exit()
print(-1)


lis = [i * i for i in range(1, 50000)]
b = input()
n = len(b)
ans = 10000000000
flag = 0
for _ in lis:
	a = str(_)
	i = j = 0
	while i < n and j < len(a):
		if b[i] == a[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(a):
		ans = min(ans, n - len(a))
		flag = 1
if flag:
	print(ans)
else:
	print(-1)


import copy

def main():
	n = int(input())
	m = copy.copy(n)
	cnt1 = 0
	cnt2 = 0
	a = [0 for i in range(10)]
	b = [0 for i in range(10)]
	while m != 0:
		a[cnt1] = m % 10
		m //= 10
		cnt1 += 1
		i = int(n ** 0.5)
	while i >= 1:
		x = i * i
		cnt2 = 0
		k = x
		i -= 1
		while x != 0:
			b[cnt2] = x % 10
			x //= 10
			cnt2 += 1
			l = 0
			j = 0
		while j < cnt1:
			if a[j] == b[l]:
				l += 1
				if l == cnt2:
					break
			j += 1
		if l == cnt2:
			print(cnt1 - l)
			return
	print(-1)
	return
main()


def valid_int(n):
	return int(round(n ** 0.5)) ** 2 == n

def valid(s):
	return valid_int(int(s))

def no_start_zero(s):
	return s[0] != '0'
n = input()

def adj(s):
	if len(s) <= 1:
		return []
	for i in range(len(s)):
		ss = s[:i] + s[i + 1:]
		if no_start_zero(ss):
			yield ss
q = [n]
seen = set()
while q:
	node = q.pop(0)
	if valid(node):
		print(len(n) - len(node))
		exit()
	for child in adj(node):
		if child not in seen:
			seen.add(child)
			q.append(child)
print(-1)


q = [str(i * i) for i in range(1, 44722)]
q.reverse()
n = input()
ans = ''
for i in q:
	cont = 0
	pos = 0
	for j in i:
		x = pos
		for k in n[x:]:
			pos += 1
			if k == j:
				cont += 1
				break
	if cont == len(i):
		ans = str(len(n) - cont)
		break
if ans == '':
	print('-1')
else:
	print(ans)


n = input()
le = len(n)
m = le
for i in range(1, 2 ** le):
	i = bin(i)[2:]
	s = ''
	c = le
	for j in range(len(i)):
		if i[-1 - j] == '1':
			s = n[le - 1 - j] + s
			c -= 1
	if s[0] == '0':
		continue
	s = int(s)
	if int(s ** (1 / 2)) ** 2 == s:
		m = min(m, c)
if m == le:
	print(-1)
else:
	print(m)


def gen(n):
	if len(a) == n:
		j = 0
		arr = []
		for i in range(n):
			if a[i] == 0:
				j *= 10
				j += int(s[i])
				arr.append(int(s[i]))
		if len(arr) > 0 and arr[0] == 0:
			return
		if j ** 0.5 == int(j ** 0.5) and j != 0:
			if sum(a) < mx[0]:
				mx[0] = sum(a)
				mx[1] = j
	else:
		a.append(0)
		gen(n)
		a[-1] = 1
		gen(n)
		a.pop()
s = input()
n = len(s)
a = []
mx = [100, 0]
gen(n)
if mx[0] != 100:
	print(mx[0])
else:
	print(-1)


x = input()
import math

def finda(n):
	root = math.sqrt(int(n))
	r = int(root)
	if r == root:
		return 0
	else:
		for i in range(r, 0, -1):
			rakm = i * i
			com = str(rakm)
			rq = 0
			j = 0
			la2eto = False
			while j < len(n):
				if n[j] == com[rq]:
					rq = rq + 1
					if rq == len(com):
						la2eto = True
						break
					j = j + 1
				else:
					j = j + 1
			if la2eto == True:
				return len(n) - len(com)
				break
		return -1
print(finda(x))


import sys
num = int(input())
for i in range(int(1000000.0), 0, -1):
	if i * i > num:
		continue
	sq = i * i
	k = 0
	for j in range(len(str(num))):
		if str(num)[j] == str(sq)[k]:
			k += 1
		if k == len(str(sq)):
			print(len(str(num)) - len(str(sq)))
			sys.exit(0)
	if i == 1:
		print(-1)
		sys.exit(0)


def ps(n):
	if n == '0':
		return False
	if str(n)[0] == '0':
		return False
	n = int(n)
	return int(math.sqrt(n)) == math.sqrt(n)
import math
l = list(input())
l = [int(i) for i in l]
n = len(l)
mini = 24
opsize = math.pow(2, n)
for counter in range(1, int(opsize)):
	y = []
	for j in range(0, n):
		if counter & 1 << j:
			y.append(l[j])
	y = ''.join((str(i) for i in y))
	if ps(y):
		mini = min(mini, n - len(y))
print(mini if mini != 24 else -1)


n = input()
INF = 987654321
res = INF
for i in range(1, 50000):
	square = list(str(i * i))
	number = list(n)
	while square and number:
		if square[-1] == number[-1]:
			square.pop()
		number.pop()
	if not square:
		res = min(res, len(n) - len(str(i * i)))
if res == INF:
	print(-1)
else:
	print(res)


a = int(input())
sa = str(a)
i = 1

def check(sa, si):
	cc = 0
	for i in range(len(sa)):
		if sa[i] == si[cc]:
			cc += 1
		if cc == len(si):
			break
	if cc == len(si):
		return True
	else:
		return False
i = int(a ** 0.5 + 1)
while i > 0:
	if i * i > a:
		i -= 1
		continue
	si = str(i * i)
	T = check(sa, si)
	if T:
		print(len(sa) - len(si))
		quit()
	i -= 1
print(-1)


import configparser
import math
import sys
input = sys.stdin.readline

def main():
	per = set()
	for i in range(int(math.sqrt(2000000000) + 5)):
		per.add(i ** 2)
	n = input().strip()
	best = 100
	for i in range(2 ** len(n)):
		res = ''
		pos = 0
		cnt = 0
		while i > 0:
			if i % 2 == 1:
				res += n[pos]
				cnt += 1
			pos += 1
			i = i >> 1
		if len(res) == 0 or res[0] == '0':
			continue
		if int(res) in per:
			best = min(best, len(n) - cnt)
	print(best if best != 100 else -1)
main()


import math

def read_data():
	n = int(input().strip())
	return n

def compare(s):
	mpos = 0
	spos = 0
	count = 0
	while spos < len(s):
		npos = m.find(s[spos], mpos)
		if npos == -1:
			return -1
		count += npos - mpos
		mpos = npos + 1
		spos += 1
	count += len(m) - mpos
	return count

def solve():
	start = int(math.sqrt(n))
	for i in range(start, 0, -1):
		c = compare(str(i * i))
		if c > -1:
			return c
	return -1
n = read_data()
m = str(n)
print(solve())


from collections import deque
d = set()
l = dict()
for i in range(1, 100000):
	d.add(str(i ** 2))
n = input()
l[n] = 0
q = deque()
q.append(n)
while len(q) > 0:
	x = q.popleft()
	if x in d:
		print(l[x])
		exit(0)
	for i in range(len(x)):
		res = x[:i] + x[i + 1:]
		if len(res) > 0 and res[0] != '0' and (res not in l):
			l[res] = l[x] + 1
			q.append(res)
print(-1)


n = input()
k = len(n)
ans = 100
for i in range(2 ** k):
	s = bin(i)[2:]
	s = '0' * (k - len(s)) + s
	sq = ''
	for j in range(k):
		if s[j] == '1':
			sq += n[j]
	if sq == '' or sq[0] == '0':
		continue
	sq = int(sq)
	l = 0
	r = 1000000
	while r - l > 1:
		c = (r + l) // 2
		if c * c > sq:
			r = c
		else:
			l = c
	if l * l == sq:
		ans = min(ans, s.count('0'))
if ans == 100:
	print(-1)
else:
	print(ans)


import math
s = input()
l1 = len(s)
l = []
for i in range(0, 2 ** l1 - 1):
	a = str(bin(i)[2:])
	b = ''
	b = (l1 - len(a)) * '0' + a
	x = ''
	for j in range(0, l1):
		if b[j] == '0':
			x += s[j]
	if x[0] != '0':
		x = int(x)
		sq = math.sqrt(x)
		if int(sq) * int(sq) == x:
			y = b.count('1')
			l.append(y)
if l == []:
	print('-1')
else:
	print(min(l))


from math import sqrt

def permutate(x):
	ll = []
	if len(x) <= 0:
		ll.append([])
	else:
		ll = []
		candi = permutate(x[1:])
		for l in candi:
			ll.append([x[0]] + l)
		ll += candi
	return ll

def main():
	x = input()
	n = len(x)
	perm = [''.join(i) for i in permutate(x) if len(i) > 0]
	perm = [i for i in perm if not i.startswith('0')]
	ans = [i for i in [int(j) for j in perm] if sqrt(i) == int(sqrt(i))]
	if len(ans) > 0:
		it = max(ans)
		print(n - len(str(it)))
	else:
		print(-1)
main()


from math import ceil, sqrt
num = input()
n = len(num)
lim = ceil(sqrt(2 * 10 ** 9))
nums = [str(int(i ** 2)) for i in range(lim, 0, -1)]
for sq in nums:
	if len(sq) > n:
		continue
	ind = 0
	for dig in sq:
		ind = num.find(dig, ind, n)
		if ind == -1:
			break
		else:
			ind += 1
	else:
		print(n - len(sq))
		break
else:
	print(-1)


import math
from itertools import chain, combinations
n = list(input())
orign = n

def valid(subset):
	m = []
	for i in range(len(subset)):
		if subset[i]:
			m.append(n[i])
	if len(m) == 0:
		return False
	if m[0] == '0':
		return False
	m = ''.join(m)
	if math.sqrt(int(m)) == int(math.sqrt(int(m))):
		return True
	return False
res = []

def subsetgen(subset, val, l):
	subset.append(val)
	s1 = subset[:]
	s2 = subset[:]
	if len(subset) == len(n):
		if valid(subset):
			res.append(l - subset.count(True))
			return True
		return False
	subsetgen(s1, True, l)
	subsetgen(s2, False, l)
	return False
subsetgen([], True, len(n))
subsetgen([], False, len(n))
if len(res) == 0:
	print(-1)
else:
	print(min(res))


def z(s):
	if s[0] == '0':
		return False
	else:
		return True
s = input()
l = len(s)
n = 0
m = 1000000000
y = n
for i in range(2 ** l):
	b = bin(n)
	n1 = ''
	b = b[0:2] + '0' * (len(s) - (len(b) - 2)) + b[2:]
	count = b.count('1')
	for i in range(l):
		if b[i + 2] == '1':
			n1 += s[i]
			count -= 1
	if len(n1) == 0:
		n1 = '0'
	if int(n1) ** 0.5 == int(int(n1) ** 0.5) and n1 != '0' and z(n1):
		x = b[2:].count('0')
		if x < m:
			m = x
	n += 1
if m == 1000000000:
	print(-1)
else:
	print(m)


from math import *
n = input()
lala = len(n)
n = '0' * 12 + n
n = n[-12:]
ans = lala
for i in range(4096):
	j = bin(i)
	j = '0' * 12 + j
	j = j[-12:]
	a = 0
	for k in range(len(j)):
		if j[k] == '1':
			a = a * 10 + int(n[k])
	x = int(sqrt(a))
	if x * x == a and x != 0:
		ans = min(ans, lala - len(str(a)))
if ans == lala:
	print(-1)
else:
	print(ans)


from math import *
strN = input()
n = int(strN)

def IsMatch(t):
	strT = str(t)
	if len(strN) == len(strT):
		if n == t:
			return 0
		else:
			return -1
	p = 0
	for c in strT:
		p = strN.find(c, p)
		if p == -1:
			break
		else:
			p += 1
	if p == -1:
		return -1
	else:
		return len(strN) - len(strT)
N = floor(sqrt(n))
for i in range(N, 0, -1):
	t = i * i
	d = IsMatch(t)
	if d >= 0:
		print(d)
		return
print(-1)


def main():
	squares = set((str(x * x) for x in range(100000)))
	s = input()
	n = len(s)
	ans = float('inf')
	for mask in range(1, 1 << n):
		o = ''.join([s[i] for i in range(n) if mask & 1 << i > 0])
		if o[0] == '0':
			continue
		if o in squares:
			pc = bin(mask).count('1')
			ans = min(ans, n - pc)
	if ans == float('inf'):
		ans = -1
	print(ans)
main()


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
x = insr()
ans = 1000000000

def perfect(n):
	a = int(math.sqrt(n))
	return a * a == n and n > 0
for i in range(1, 1 << len(x)):
	n = 0
	cnt = 0
	for j in range(len(x)):
		if i & 1 << j:
			n *= 10
			n += int(x[j])
		else:
			cnt += 1
	if perfect(n) and len(str(n)) + cnt == len(x):
		ans = min(ans, cnt)
if ans == 1000000000:
	print(-1)
else:
	print(ans)


from math import sqrt
st = input()
l = int(sqrt(int(st)) + 1)
sqrs = [str(x * x) for x in range(1, l)]
for sqr in reversed(sqrs):
	i = -1
	for ch in list(sqr):
		i = st.find(ch, i + 1)
		if i == -1:
			break
	else:
		print(str(len(st) - len(sqr)))
		exit()
print(-1)


n = input()
count = len(n)
rad = int(int(n) ** 0.5) + 1

def check(s):
	if s == '':
		return False
	if s[0] == '0':
		return False
	z = int(s)
	return int(z ** 0.5) ** 2 == z
sub = [[]]
for i in range(count):
	X = []
	for j in sub:
		X.append(j + [i])
	sub += X
out = 10
for i in sub:
	A = [1] * (count + 5)
	for j in i:
		A[j] = 0
	s = ''
	for j in range(count):
		if A[j] == 1:
			s += n[j]
	if check(s):
		out = min(out, len(i))
if out == 10:
	print(-1)
else:
	print(out)


n = int(input())
s = str(n)
l = []
for w in range(round(n ** 0.5), 0, -1):
	k = str(w ** 2)
	x = 0
	for (i, j) in enumerate(s):
		if k != '' and j == k[0]:
			k = k[1:]
		elif k != '' and j != k[0]:
			x += 1
		elif k == '':
			x += len(s[i])
	if k == '':
		l.append(x)
if l == []:
	print(-1)
else:
	print(min(l))


def isSubSequence(subString, string, m=-1, n=-1):
	if m == -1:
		m = len(subString)
	if n == -1:
		n = len(string)
	if m == 0:
		return True
	if n == 0:
		return False
	if subString[m - 1] == string[n - 1]:
		return isSubSequence(subString, string, m - 1, n - 1)
	return isSubSequence(subString, string, m, n - 1)
n = input()
L = [str(e * e) for e in range(1, 100000)]
l = len(L)
for k in range(l):
	if isSubSequence(L[-k - 1], n):
		print(len(n) - len(L[-k - 1]))
		exit()
print(-1)


from math import sqrt

def solve(i, val):
	global ans
	if i == len(n):
		if val and (not val.startswith('0')) and sqrt(int(val)).is_integer() and (len(val) > ans):
			ans = len(val)
		return
	solve(i + 1, val)
	solve(i + 1, val + n[i])
n = list(input())
ans = 0
solve(0, '')
print(len(n) - ans if ans else -1)


import itertools
a = []
for i in range(1, 44722):
	a.append(i * i)
n = input()
for i in range(len(n), 0, -1):
	for j in itertools.combinations(n, i):
		s = ''
		for k in j:
			s += k
		if s[0] != '0' and int(s) in a:
			print(len(n) - i)
			exit()
print(-1)


squares = set()
x = 1
while x * x <= 2 * 10 ** 9:
	squares.add(x * x)
	x += 1
n = input()
l = len(n)

def masked(x, mask):
	pow10 = 1
	y = 0
	while x > 0:
		if mask % 2 == 1:
			y += x % 10 * pow10
			pow10 *= 10
		x //= 10
		mask //= 2
	return y
if int(n) in squares:
	print(0)
else:
	minOp = len(n)
	for mask in range(2 ** l):
		x = masked(int(n), mask)
		if x in squares:
			minOp = min(minOp, len(n) - len(str(x)))
	print(minOp if minOp < len(n) else -1)


from math import floor, sqrt

def is_square(num):
	return floor(sqrt(num)) ** 2 == num
n = input()
l = len(n)
NUM = 2 ** l
maxcnt = 0
for i in range(1, NUM):
	s = ''
	for j in range(l):
		if i & 1 << j:
			s += n[j]
	if is_square(int(s)):
		cnt = len(s.lstrip('0'))
		maxcnt = max(maxcnt, cnt)
if maxcnt == 0:
	maxcnt = l + 1
print(l - maxcnt)


def get_list(func=None):
	if not func:
		return input().split()
	return list(map(func, input().split()))

def edit_dist(A, a, v=False):
	if v:
		print(A, a)
	if len(A) < len(a):
		return -1
	if len(a) == 0:
		return len(A)
	mind = float('inf')
	for (i, ch) in enumerate(A):
		if ch == a[0]:
			d = edit_dist(A[i + 1:], a[1:], v)
			if d != -1:
				mind = min(mind, d + i)
	if mind < float('inf'):
		return mind
	return -1
n = input()
mind = float('inf')
for i in range(1, 44800):
	s = str(i ** 2)
	d = edit_dist(n, s)
	if d != -1 and mind > d:
		mind = d
		ansi = s
if mind > 100:
	print(-1)
else:
	print(mind)


def is_sqr(x):
	y = 1
	while y ** 2 < x:
		y += 1
	return y ** 2 == x
from itertools import combinations
n = input()
ans = 100
for r in range(1, len(n) + 1):
	for item in combinations(n, r):
		if is_sqr(int(''.join(item))) and item[0] != '0':
			ans = min(ans, len(n) - len(item))
print(ans if ans != 100 else -1)


n = input()
m = int(int(n) ** 0.5)
n = list(n)
while m > 0:
	nm = str(m ** 2)
	j = 0
	for i in range(len(n)):
		if n[i] == nm[j]:
			j += 1
			if j == len(nm):
				exit(print(len(n) - j))
	m -= 1
print(-1)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def fastPrintNextLines(a):
	print('\n'.join(map(str, a)))
from itertools import chain, combinations

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
for i in range(t):
	s = list(si())
	q = len(s)
	s = list(power_set(s))
	m = 1000000000000000000000
	for i in range(len(s)):
		n = ''.join(s[i])
		if n == '':
			continue
		n = int(n)
		if len(str(n)) != len(s[i]) or n == 0:
			continue
		x = n ** 0.5
		if x == int(x):
			m = min(m, q - len(s[i]))
	if m == 1000000000000000000000:
		m = -1
	print(m)


from math import sqrt
n = int(input())
x = sqrt(n)
if x == int(x):
	print(0)
else:
	for i in range(int(x), 0, -1):
		y = str(i ** 2)
		c = 0
		for j in str(n):
			if j == y[c]:
				c += 1
			if c == len(y):
				break
		if c == len(y):
			print(len(str(n)) - c)
			break
	else:
		print(-1)


import math

def solve(num, count):
	if len(num) == 0:
		return
	if num[0] == '0':
		return
	if num in cache:
		return
	number = int(num)
	root = math.sqrt(number)
	if int(root) ** 2 == number:
		if count['min'] == -1:
			count['min'] = count['value']
			cache[num] = True
		else:
			count['min'] = min(count['value'], count['min'])
			cache[num] = True
		return
	for i in range(len(num)):
		newnum = num[:i] + num[i + 1:]
		count['value'] += 1
		solve(newnum, count)
		cache[newnum] = True
		count['value'] -= 1
	return
counter = {'value': 0, 'min': -1}
cache = {}
data = input()
solve(data, counter)
answer = counter['min']
print(answer if answer != -1 else '-1')


from math import *
n = input()
for i in range(floor(sqrt(int(n))), 0, -1):
	a = list(n)
	b = list(str(i * i))
	bn = len(b)
	while a and b:
		if a[-1] == b[-1]:
			b.pop()
		a.pop()
	if not b:
		print(len(n) - bn)
		exit()
print(-1)


from math import sqrt
n = int(input())
b = []
mass = []
for i in range(int(sqrt(n))):
	b.append(str((i + 1) ** 2))
n = list(str(n))
for i in range(len(b)):
	s = 0
	aaa = 0
	for l in range(len(b[i])):
		try:
			s = n.index(b[i][l], s) + 1
		except:
			aaa = 1
			break
	if aaa == 0:
		mass.append(b[i])
mass.sort(key=len)
try:
	print(len(n) - len(mass[-1]))
except:
	print(-1)


sq = [0] * 50000
for i in range(50000):
	sq[i] = i * i
s = input()
for k in range(49999, 0, -1):
	t = str(sq[k])
	if len(t) <= len(s):
		j = 0
		i = 0
		while j < len(s) and i < len(t):
			if t[i] == s[j]:
				i += 1
				j += 1
			else:
				j += 1
		if i == len(t):
			print(len(s) - len(t))
			exit()
print('-1')


from math import *

def sqr(f):
	return sqrt(f) == int(sqrt(f))

def bine(x, ln):
	b = bin(int(x))[2:]
	return '0' * (ln - len(b)) + b
n = input()
ln = len(n)
R = 10 ** 10
for i in range(1, 2 ** len(n)):
	s = ''
	b = bine(i, ln)
	R1 = b.count('0')
	if R1 < R:
		for j in range(ln):
			if b[j] == '1':
				s += n[j]
		if sqr(int(s)) and len(s) == len(str(int(s))) and (s != '0'):
			R = R1
if R == 10 ** 10:
	print(-1)
else:
	print(R)


import itertools
import math
n = int(input())
if int(math.sqrt(n)) == math.sqrt(n):
	print(0)
else:
	st = str(n)
	L = len(st)
	nums = []
	for i in range(1, L):
		u = set(itertools.combinations(st, i))
		for x in u:
			num = ''
			for k in x:
				num += str(k)
			nums.append(num)
	results = []
	for x in nums:
		n = int(x)
		if x[0] != '0' and int(math.sqrt(n)) == math.sqrt(n):
			results.append(L - len(x))
	if len(results) == 0:
		print(-1)
	else:
		print(min(results))


import sys

def get_square_literal_map():
	literal_map = {}
	for i in range(1, 44722):
		literal = str(i * i)
		literal_len = len(literal)
		if literal_len not in literal_map:
			literal_map[literal_len] = set()
		literal_map[literal_len].add(literal)
	return literal_map

def is_subsequence(x, y):
	it = iter(y)
	return all((any((c == ch for c in it)) for ch in x))

def main():
	literal_map = get_square_literal_map()
	n = int(sys.stdin.readline())
	n_literal = str(n)
	n_len = len(n_literal)
	for i in range(n_len, 0, -1):
		for j in literal_map[i]:
			if is_subsequence(j, n_literal):
				found = True
				print(n_len - i)
				return
	print(-1)
sys.exit(main())


n = input()
l = len(n)
res = 1000000
for x in range(1, 2 ** l):
	g = x
	s = ''
	i = 0
	while g:
		if g % 2:
			s += n[i]
		g //= 2
		i += 1
	if s.startswith('0'):
		continue
	h = int(s)
	sq = h ** 0.5
	if sq == int(sq):
		res = min(res, l - len(s))
print(res if res != 1000000 else -1)


import sys
import math
from functools import lru_cache

@lru_cache(maxsize=None)
def solution(nstr, nint, acc):
	msf = float('inf')
	if math.sqrt(nint) - int(math.sqrt(nint)) == 0.0:
		return acc
	for i in range(len(nstr)):
		mstr = nstr[:i] + nstr[i + 1:]
		if mstr:
			if mstr[0] == '0':
				continue
			msf = min(msf, solution(mstr, int(mstr), acc + 1))
	if msf == float('inf'):
		return float('inf')
	return msf
n = sys.stdin.readline().strip()
res = solution(n, int(n), 0)
if res == float('inf'):
	print(-1)
else:
	print(res)


import math

def isSquare(x):
	return int(math.sqrt(x)) ** 2 == x

def dp(ch, i=0):
	if ch == '0':
		return ''
	if len(ch) == 1:
		if isSquare(int(ch)) and ch[0] != '0':
			return ch
		else:
			return ''
	if ch[0] == '0':
		return dp(ch[1:], max(i - 1, 0))
	if i >= len(ch):
		if isSquare(int(ch)):
			return ch
		else:
			return ''
	if isSquare(int(ch)):
		return ch
	else:
		c = list(ch[:])
		c[i] = ''
		c = ''.join(c)
		return max(dp(ch, i + 1), dp(c, i), key=len)
ch = input()
sh = dp(ch)
if len(sh) == 0:
	print(-1)
else:
	print(len(ch) - len(sh))


import math
from sys import stdin
from math import ceil
import sys
from math import sqrt
number = input()
radix = sqrt(int(number))
for i in range(int(radix), 0, -1):
	x = list(number)
	y = list(str(i * i))
	numbOperations = len(number) - len(y)
	while x and y:
		if x[-1] == y[-1]:
			y.pop()
		x.pop()
	if not y:
		print(numbOperations)
		sys.exit()
print(-1)


n = input()
k = []
for i in range(1, 100000):
	k.append(str(i * i))
l = []
for i in k:
	if int(i) <= int(n):
		j = 0
		o = 0
		while j < len(n) and o < len(i):
			if n[j] == i[o]:
				o += 1
			j += 1
		if o == len(i):
			l.append(i)
	else:
		break
if len(l) > 0:
	print(len(n) - len(l[-1]))
else:
	print('-1')


n = input()
a = []
for i in range(1, int((2 * 10 ** 9) ** 0.5) + 1):
	a.append(i ** 2)
m = float('inf')
l = len(n)
for i in range(1, 2 ** len(n)):
	bi = bin(i)[2:]
	bi = '0' * (l - len(bi)) + bi
	ne = ''
	for i in range(l):
		if bi[i] == '1':
			ne += n[i]
	if ne[0] == '0':
		continue
	elif int(ne) in a:
		m = min(m, bi.count('0'))
if m == float('inf'):
	print(-1)
else:
	print(m)


def correct(ar, ar2, n):
	for i in range(n):
		if ar2[i] == '0':
			continue
		if ar[i] == '0':
			return 0
		return 1

def is_square(ar, ar2, n):
	s = ''
	for i in range(n):
		if ar2[i] == '1':
			s += ar[i]
	num = int(s)
	num2 = int(num ** 0.5)
	if num2 * num2 == num:
		return 1
	return 0

def count_act(ar2):
	num = 0
	for i in ar2:
		if i == '0':
			num += 1
	return num

def form_bin_num(ar2, n):
	n2 = len(ar2)
	ar = '0' * (n - n2)
	for i in ar2:
		ar += i
	return ar
num = list(input())
n = len(num)
num2 = 2 ** n
mini = 100
for i in range(1, num2):
	ar2 = form_bin_num(bin(i)[2:], n)
	if correct(num, ar2, n) == 0:
		continue
	if is_square(num, ar2, n) == 1:
		mini = min(mini, count_act(ar2))
if mini == 100:
	print(-1)
else:
	print(mini)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def main():
	try:
		n = I()
		l1 = str(n)
		d = {}
		ans = -1
		l = []
		i = 1
		while i ** 2 <= n:
			l.append(i ** 2)
			i += 1
		n1 = len(l1)
		for x in l:
			t = str(x)
			i = 0
			count = 0
			for j in range(len(t)):
				while i < n1:
					if l1[i] == t[j]:
						count += 1
						i += 1
						break
					else:
						i += 1
			if count == len(t):
				if ans == -1:
					ans = len(t)
				else:
					ans = max(ans, len(t))
		if ans == -1:
			print(-1)
		else:
			print(n1 - ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


def f(s, i):
	if len(s) > 0 and s[0] != '0':
		ss = int(s)
		x = int(ss ** 0.5 + 0.5)
		if x * x == ss and x > 0:
			return 0
	r = 1000
	for j in range(i, len(s)):
		r = min(r, 1 + f(s[:j] + s[j + 1:], j))
	return r
n = input()
r = f(n, 0)
if r >= 1000:
	print(-1)
else:
	print(r)


from functools import reduce
from math import log10
n = int(input())
nums = [n // 10 ** i % 10 for i in range(int(log10(n) + 1)) if 10 ** i <= n]
res = 0
l = len(nums)
for mask in range(1 << l):
	mas = list(reversed([nums[bit] for bit in range(l) if mask & 1 << bit]))
	if not mas or mas[0] == 0:
		continue
	quad = reduce(lambda x, y: 10 * x + y, mas)
	if quad == int(quad ** (1 / 2)) ** 2:
		res = max(res, len(mas))
print(-1 if res == 0 else l - res)


import math

def solve(X):
	if math.sqrt(X) == math.sqrt(X) // 1:
		return 0
	X = str(X)
	prev = [X]
	for k in range(1, len(X)):
		curr = []
		for num in prev:
			for i in range(len(X) - k + 1):
				newnum = num[:i] + num[i + 1:]
				if newnum[0] == '0':
					continue
				curr.append(newnum)
				newnum = int(newnum)
				if math.sqrt(newnum) == math.sqrt(newnum) // 1:
					return k
		prev = curr
	return -1
X = int(input())
ans = solve(X)
print(ans)


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)
k.reverse()
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)


import math

def dec(a):
	global e, min, z, zz
	z = -1
	i = len(e) - len(a)
	if len(a) == 0:
		return None
	a1 = float(''.join([str(s) for s in a]))
	if zz.count(a1) == 0:
		zz.append(a1)
	else:
		return None
	if math.sqrt(a1) == int(math.sqrt(a1)) and i < min:
		min = i
	else:
		i += 1
		for b in range(len(a)):
			c = a[:b] + a[b + 1:]
			if c.count('0') > 0:
				for l in range(c.count('0')):
					if c[0] == '0':
						c.remove('0')
			dec(c)
	if min == len(a):
		return z
	else:
		return min
e = list(input())
min = len(e)
zz = []
print(dec(e))


from sys import stdout
from sys import stdin

def get():
	return stdin.readline().strip()

def getf():
	return [int(i) for i in get().split()]

def put(a, end='\n'):
	stdout.write(str(a) + end)

def putf(a, sep=' ', end='\n'):
	stdout.write(sep.join(map(str, a)) + end)

def mul(a, s, k):
	t = ''
	for i in range(k):
		if s[i] == '1':
			t += str(a[i])
	n = int(t)
	if int(n ** 0.5) ** 2 == n and t[0] != '0':
		return True
	return False

def main():
	n = int(get())
	a = []
	k = 1
	p = 0
	while n:
		a.insert(0, n % 10)
		n //= 10
		k *= 2
		p += 1
	ans = 10 ** 9
	for i in range(1, k):
		s = ('0000000000' + bin(i)[2:])[-p:]
		if mul(a, s, p):
			ans = min(ans, s.count('0'))
	if ans != 10 ** 9:
		put(ans)
	else:
		put(-1)
main()


st = set()
for i in range(1, 50000):
	st.add(i * i)
from itertools import combinations
ans = -1
s = input()
for i in range(1, len(s) + 1):
	for com in combinations(s, i):
		if com[0] == '0':
			continue
		if int(''.join(com)) in st:
			ans = max(ans, i)
print(-1 if ans == -1 else len(s) - ans)


n = input()
k = int(n)
i = 2
rec = [1]
INF = float('inf')
while i * i <= k:
	rec.append(i * i)
	i += 1
num = INF
for i in rec:
	t = str(i)
	q = 0
	for j in range(len(n)):
		if t[q] == n[j]:
			q += 1
		if q == len(t):
			num = min(num, len(n) - len(t))
			break
if num == INF:
	print(-1)
else:
	print(num)


ar = []
for i in range(1, 10 ** 5):
	if i * i > 2 * 10 ** 9:
		break
	ar.append(i * i)
s = input()
ans = len(s)
for x in ar:
	s2 = str(x)
	i = 0
	for x in range(len(s)):
		if i < len(s2) and s[x] == s2[i]:
			i += 1
	if i == len(s2):
		ans = min(ans, len(s) - i)
if ans == len(s):
	print(-1)
else:
	print(ans)


from math import sqrt, floor
s = input()
l = len(s)
d = []
for i in range(2 ** l):
	c = ''
	flag = True
	for j in range(1, l + 1):
		if i & 1 << j - 1:
			if flag == True:
				if s[j - 1] == '0':
					flag = False
					break
				else:
					flag = False
					c += s[j - 1]
			else:
				c += s[j - 1]
	if len(c) > 0 and int(c) != 0:
		d.append(c)
d = sorted(d, key=len, reverse=True)
for i in d:
	s = sqrt(int(i))
	if s - floor(s) == 0:
		print(l - len(i))
		break
else:
	print('-1')


N = 44722
a = []
for i in range(N):
	if i == 0:
		continue
	a.append(str(i * i))
s0 = input()
l = len(s0)
ans = -1
for s in a:
	ls = len(s)
	if ls > l:
		break
	flag = False
	num = 0
	j = 0
	for i in range(l):
		if s0[i] == s[j]:
			num += 1
			j += 1
		if num == ls:
			flag = True
			break
	if flag:
		ans = max(ans, num)
if ans != -1:
	ans = l - ans
print(ans)


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)

def ok(n, x):
	global sq
	a = []
	for i in range(len(n)):
		if x & 1:
			a.append(n[i])
		x = x >> 1
	a = ''.join(a)
	if a in sq:
		return len(n) - len(a)
	return -1
i = 1
sq = set()
while i * i <= 2 * 10 ** 9:
	sq.add(str(i * i))
	i += 1
n = input()
ans = None
for i in range(1 << len(n)):
	t = ok(n, i)
	if t == -1:
		continue
	if ans is None:
		ans = t
	else:
		ans = min(ans, t)
if ans is None:
	ans = -1
print(ans)


from math import sqrt

def contain(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	(i, j) = (0, 0)
	while i < l1 and j < l2:
		while i < l1 and s1[i] != s2[j]:
			i += 1
		if i < l1 and j < l2 and (s1[i] == s2[j]):
			i += 1
			j += 1
	if j >= l2:
		return True
	else:
		return False
n = int(input())
m = int(sqrt(n))
ans = -1
for i in range(m, 0, -1):
	if contain(str(n), str(i * i)):
		ans = len(str(n)) - len(str(i * i))
		break
print(ans)


a = input()
x = []
ans = -1
for i in a:
	y = x.copy()
	for t in y:
		x.append(t * 10 + int(i))
	if i != '0':
		x.append(int(i))
for i in x:
	j = int(i ** 0.5)
	if j * j == i:
		d = len(a) - len(str(i))
		if ans == -1:
			ans = d
		else:
			ans = min(ans, d)
print(ans)


import math
n = input()
count = len(n)
minop = 10

def dv(x):
	l = ''
	while x > 0:
		if x % 2 == 0:
			l += '0'
		else:
			l += '1'
		x //= 2
	l = '0' * (count - len(l)) + l[::-1]
	return l

def number(num, key):
	l = ''
	for i in range(len(num)):
		if key[i] == '1':
			l += num[i]
	return l

def check(p):
	if math.sqrt(p) - int(math.sqrt(p)) == 0:
		return True
	else:
		return False
for i in range(1, 2 ** count):
	key = dv(i)
	num = number(n, key)
	if num[0] == '0':
		continue
	else:
		num = int(num)
		if check(num) == True:
			delete = key.count('0')
			minop = min(delete, minop)
if minop == 10:
	print(-1)
else:
	print(minop)


from collections import Counter
from math import sqrt, floor
n = input()
n_ = Counter(map(int, n))
s = n_.keys()
ln = len(n)
ans = ln
for i in range(1, floor(sqrt(int(n))) + 1):
	a = str(i ** 2)
	a_ = Counter(map(int, a))
	ln_a = len(a)
	if a_.keys() <= s:
		for (k, v) in a_.items():
			if n_[k] < v:
				break
		else:
			temp_n = n
			for el in a:
				if temp_n == str():
					break
				try:
					temp_n = temp_n[temp_n.index(el) + 1:]
				except ValueError:
					break
			else:
				ans = min(ans, ln - ln_a)
print((-1, ans)[ans < ln])


from itertools import *

def main():
	a = input()
	for i in range(len(a) + 1, 0, -1):
		for a_i in combinations(a, i):
			if a_i[0] != '0':
				n = int(str(''.join(a_i))) ** 0.5
				if n - int(n) == 0:
					print(len(a) - i)
					return
	print(-1)
	return
main()


import math

def validate(number):
	if math.sqrt(number).is_integer():
		return True
	else:
		return False

def inp_queue(number):
	global queue
	c = 0
	while c < len(number):
		number_new = []
		for i in range(0, len(number)):
			if i != c:
				number_new.insert(i, number[i])
		result = ''.join(number_new)
		if result not in queue:
			if int(result) != 0:
				queue.append(result)
		c = c + 1
	return queue

def get_max(array):
	values = []
	for i in range(0, len(array)):
		values.append(array[i])
	value = max(values)
	return value
n = input()
queue = [n]
square = []
while len(queue) > 0:
	n_square = queue.pop(0)
	validation = validate(int(n_square))
	if validation == False:
		if len(n_square) > 1:
			new_queue = inp_queue(n_square)
	else:
		square.append(int(n_square))
if square == []:
	print('-1')
else:
	result_square = str(get_max(square))
	if result_square[0] == '0':
		output = len(n) - len(result_square) + 1
	else:
		output = len(n) - len(result_square)
	print(output)


from math import sqrt
import sys
n = input()
for i in range(int(sqrt(int(n))), 0, -1):
	x = list(n)
	y = list(str(i * i))
	nops = len(n) - len(y)
	while x and y:
		if x[-1] == y[-1]:
			y.pop()
		x.pop()
	if not y:
		print(nops)
		sys.exit()
print(-1)


n = int(input())
i = 1
ans = 12
while i * i <= n:
	s = str(n)
	t = str(i * i)
	d = 0
	j = 0
	no = 0
	for k in t:
		if no or j == len(s):
			no = 1
			break
		while s[j] != k:
			j += 1
			d += 1
			if j == len(s):
				no = 1
				break
		j += 1
	while j < len(s):
		d += 1
		j += 1
	if not no and ans > d:
		ans = d
	i += 1
print(ans if ans < 12 else -1)


import sys
import math
on = None
ans = 100
x = -1

def is_square(x):
	decimal = math.sqrt(x) - math.floor(math.sqrt(x))
	return decimal == 0

def check_number():
	digits = [x[i] for i in range(len(x)) if on[i]]
	if digits and int(digits[0]):
		num = 0
		for digit in digits:
			num = 10 * num + int(digit)
		if is_square(num):
			global ans
			ans = min(ans, len(x) - len(digits))

def recurse(idx):
	if idx == len(on):
		check_number()
		return
	on[idx] = True
	recurse(idx + 1)
	on[idx] = False
	recurse(idx + 1)
input_ = sys.stdin.read().split()
x = input_[0]
on = [False for _ in range(len(x))]
recurse(0)
print(-1 if ans == 100 else ans)


import itertools
import math
squre = []
for i in range(5000):
	squre.append(i * i)
n = input()
l = [int(i) for i in n]
s = len(l)
c = 100
for i in range(s, 0, -1):
	a = list(itertools.combinations(l, i))
	for j in a:
		if j[0] == 0:
			continue
		temp = 0
		for k in j:
			temp = temp * 10 + k
		b = int(math.sqrt(temp))
		if b * b == temp:
			c = min(c, s - i)
if c == 100:
	print(-1)
else:
	print(c)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	q = math.ceil(math.sqrt(n))
	ans = 100
	while q > 0:
		temp = q * q
		(s, t) = (str(n), str(temp))
		(i, j) = (0, 0)
		while i < len(s):
			if j == len(t):
				break
			if t[j] == s[i]:
				i += 1
				j += 1
			else:
				i += 1
		if j == len(t):
			ans = min(ans, len(s) - len(t))
		q -= 1
	print(ans if ans != 100 else -1)
main()


from math import sqrt, floor
from collections import deque

def subsequence(s, binary, length):
	sub = ''
	for j in range(length):
		if binary & 1 << j:
			sub += s[j]
	return sub
n = input()
length = len(n)
limit = 1 << length
res = deque()
for i in range(1, limit):
	ss = subsequence(n, i, length)
	a = int(ss)
	if ss[0] != '0' and floor(sqrt(a)) == sqrt(a):
		res.append(a)
if len(res) != 0:
	ans = '{}'.format(max(res))
	print(len(n) - len(ans))
else:
	print(-1)


INF = float('inf')

def isSqrt(s):
	if s[0] == '0':
		return False
	n = int(s)
	m = 0
	while m * m <= n:
		if m * m == n:
			return True
		m += 1
	return False
s = list(input())
n = len(s)
ret = INF
for mask in range((1 << n) - 1):
	t = s[:]
	for i in range(n):
		if mask >> i & 1 == 1:
			t[i] = ''
	if isSqrt(''.join(t)):
		ret = min(ret, bin(mask).count('1'))
print(ret if ret != INF else -1)


n = input()
ps = []
for i in range(44722):
	ps.append(str(i * i))
ans = 20
for i in range(1, 44722):
	k = 0
	l = len(ps[i])
	for j in n:
		if j == ps[i][k]:
			k += 1
		if k == l:
			break
	if k == l:
		ans = min(ans, len(n) - l)
if ans == 20:
	ans = -1
print(ans)


def n_in_k(n, k):
	k = list(str(k))
	for digit in str(n):
		try:
			d_k = k.index(digit)
			k = k[d_k + 1:]
		except:
			return False
	return True
n = int(input())
squares = []
for i in range(1, n + 1):
	sq = i * i
	if sq > n:
		break
	else:
		squares.append(sq)
for sq in reversed(squares):
	if n_in_k(sq, n):
		print(len(str(n)) - len(str(sq)))
		exit()
print(-1)


n = int(input())
m = n
__len = 0
while m > 0:
	m //= 10
	__len += 1
digs = list(str(n))
ans = -1
from math import sqrt

def check_sq(numb):
	al = int(sqrt(numb))
	for i in range(al - 1, al + 2):
		if i * i == numb:
			return True
	return False

def check_null(mask):
	was = False
	for i in range(__len):
		if mask[i] == '1' and digs[i] == '0' and (not was):
			return False
		if mask[i] == '1' and digs[i] != '_':
			was = True
	return True

def check(mask):
	num = 0
	if not check_null(mask[::-1]):
		return False
	_pow = 0
	for i in range(__len):
		if mask[i] == '1':
			num += 10 ** _pow * int(digs[-i - 1])
			_pow += 1
	return num != 0 and check_sq(num)

def ed_num(mask):
	res = 0
	for el in mask:
		if el == '0':
			res += 1
	return res
for i in range(2 ** __len):
	a = bin(i)[2:]
	b = list('0' * (__len - len(a)) + a)
	if check(b):
		if ans == -1:
			ans = ed_num(b)
		else:
			ans = min(ans, ed_num(b))
print(ans)


def dfs(u):
	global ans, choose, l
	if u == l:
		get_ans()
		return
	choose[u] = False
	dfs(u + 1)
	choose[u] = True
	dfs(u + 1)

def get_ans():
	global ans, choose, s
	tem = ''
	for i in range(l):
		if choose[i]:
			tem += s[i]
		else:
			continue
	if len(tem) == 0:
		return
	else:
		tem = tem.lstrip('0')
		if len(tem) == 0:
			return
		else:
			val = int(tem)
			a = int(pow(val, 0.5))
			if a ** 2 == val:
				ans = max(ans, len(tem))
				return
			else:
				return
s = input()
l = len(s)
ans = -1
choose = [i for i in range(l)]
dfs(0)
if ans != -1:
	ans = l - ans
print(ans)


import atexit
import io
import sys
import math
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	n = input()
	mm = 0
	for i in range(1, 2 ** len(n)):
		x = ''
		for c in range(len(n)):
			if i % 2:
				x += n[c]
			i = i // 2
		if x[0] == '0':
			continue
		xx = int(x)
		if int(xx ** 0.5) ** 2 == xx:
			if len(x) > mm:
				mm = len(x)
	print(len(n) - mm if mm > 0 else -1)
main()


from math import sqrt
a = input()
i = 0
r = 1000000000.0
while True:
	i += 1
	if i == 1 << len(a):
		break
	c = ''
	for (id, j) in enumerate(a):
		if i & 1 << id:
			c += j
	if c[0] == '0':
		continue
	sq = int(sqrt(int(c)))
	if sq * sq == int(c):
		r = min(r, len(a) - len(c))
if r == 1000000000.0:
	print(-1)
else:
	print(r)


q = int(input())
pot = []
b = 1
while 42:
	a = b ** 2
	if a <= q:
		pot.append(a)
		b += 1
	else:
		break
pot.sort(reverse=True)
q = list(str(q))
j = 0
l = 0
flag = 0
for i in range(len(pot)):
	l = 0
	for j in range(len(q)):
		if q[j] == list(str(pot[i]))[l]:
			l += 1
		if l == len(str(pot[i])):
			flag = 1
			break
	if flag == 1:
		print(len(q) - len(str(pot[i])))
		break
if flag == 0:
	print(-1)


squares = []
for i in range(1, 100000):
	squares.append(str(i * i))
	if int(squares[-1]) > 2000000000:
		break
n = input()
ans = 1000

def deletions(source, target):
	pt = 0
	for i in source:
		if i == target[pt]:
			pt += 1
		if pt == len(target):
			break
	if pt == len(target):
		return len(source) - len(target)
	else:
		return 1000
for i in squares:
	ans = min(ans, deletions(n, i))
if ans < 1000:
	print(ans)
else:
	print(-1)


from math import sqrt
num = int(input())

def inString(i, num):
	i = str(i)
	num = str(num)
	cur_term = 0
	for j in range(len(num)):
		if num[j] == i[cur_term]:
			cur_term += 1
			if cur_term == len(i):
				return True
	return False
ansNotFound = True
for i in range(int(sqrt(num)) + 1, 0, -1):
	if inString(i * i, num):
		print(len(str(num)) - len(str(i * i)))
		ansNotFound = False
		break
if ansNotFound:
	print(-1)


import math

def is_p_square(elem):
	raiz = int(math.sqrt(elem))
	return raiz ** 2 == elem
s = input()
tam = len(s)
tam2 = -1
fila = [s]
found = False
while len(fila) > 0:
	s_elem = fila.pop(0)
	tam2 = len(s_elem)
	if tam2 > 0:
		elem = int(s_elem)
	if is_p_square(elem):
		found = True
		break
	ultimo_removido = s[0]
	primeira_vez = True
	for i in range(tam2):
		nova_str = s_elem[:i] + s_elem[i + 1:]
		if len(nova_str) >= 1 and nova_str[0] != '0':
			if primeira_vez:
				ultimo_removido = s_elem[i]
				fila.append(nova_str)
				primeira_vez = False
			elif s_elem[i] != ultimo_removido:
				ultimo_removido = s_elem[i]
				fila.append(nova_str)
if found:
	print(tam - tam2)
else:
	print('-1')


from collections import defaultdict
N = input().strip()
squares = [str(i ** 2) for i in range(1, 45000)][::-1]
for i in squares:
	is_good = True
	cur_idx = 0
	for j in N:
		if j == i[cur_idx]:
			cur_idx += 1
			if cur_idx >= len(i):
				break
	if cur_idx == len(i):
		print(len(N) - len(i))
		exit(0)
print(-1)


from itertools import chain, combinations

def powerset(iterable):
	s = list(iterable)
	return chain.from_iterable((combinations(s, r) for r in range(len(s) + 1)))

def is_sq(n):
	if n < 1:
		return False
	for i in range(n + 1):
		if i * i == n:
			return True
		elif i * i > n:
			break
	return False
n = list(input())
ps = reversed(list(powerset(n)))
ans = -1
for p in ps:
	if len(p) > 0 and p[0] is not '0':
		nu = int(''.join(p))
		if is_sq(nu):
			ans = len(n) - len(p)
			break
print(ans)


from math import sqrt, floor
n = input()

def is_square(n):
	f = floor(sqrt(n))
	return f * f == n or (f + 1) * (f + 1) == n

def min_to_square(d, n):
	if len(n) == 1:
		return d if is_square(int(n)) else 100
	if n[0] == '0':
		return 100
	if n[0] != '0' and is_square(int(n)) or n == '0':
		return d
	m = min([min_to_square(d + 1, n[:i] + n[i + 1:]) for i in range(len(n))])
	return m

def mts(n):
	min_ = 100
	for i in range(1, 2 ** len(n)):
		s = '{0:b}'.format(i).zfill(len(n))
		newn = ''.join([n[i] for i in range(len(n)) if s[i] == '1'])
		if is_square(int(newn)) and newn[0] != '0':
			min_ = min(min_, sum((1 for c in s if c == '0')))
	return min_
print(mts(n) if mts(n) < 100 else -1)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
from math import sqrt
l = list(map(int, ss()))
p = len(l)
ans = 3000000000
for n in range(1, 2 ** p):
	c = 1
	t = 0
	st = 0
	while n:
		if n & 1:
			t = t * 10 + l[c - 1]
			if t:
				st += 1
		n = n >> 1
		c += 1
	if sqrt(t).is_integer() and t:
		ans = min(p - st, ans)
if ans != 3000000000:
	print(ans)
else:
	print(-1)


s = input()
res = 10 ** 10
for i in range(1, 10 ** 6):
	if i * i > int(s):
		break
	t = str(i * i)
	p = 0
	for x in s:
		if x == t[p]:
			p += 1
			if p == len(t):
				break
	if p == len(t):
		res = min(res, len(s) - len(t))
if res == 10 ** 10:
	res = -1
print(res)


_2 = list()
for i in range(1, 10 ** 5):
	tmp = i * i
	if tmp > 2 * 10 ** 9:
		break
	_2.append(tmp)
s = set(_2)
dig = list()
cnt = 0
for x in map(ord, input()):
	x = x - 48
	dig.append(x)
	cnt = cnt + 1
ans = -1
lim = 1 << cnt
for sta in range(1, lim):
	now = 0
	c = 0
	ok = True
	for j in range(cnt):
		if sta & 1 << j:
			if c == 0 and dig[j] == 0:
				ok = False
				break
			c = c + 1
			now = now * 10 + dig[j]
	if not ok:
		continue
	if now in s:
		if ans == -1:
			ans = cnt - c
		else:
			ans = min(ans, cnt - c)
print(ans)


import sys
import math as mt
import bisect
t = 1

def sqt(x):
	l1 = []
	i = 1
	while i * i <= n:
		l1.append(str(i * i))
		i += 1
	return l1

def solve():
	nums = sqt(n)
	d = {}
	s = str(n)
	for i in range(len(s)):
		if d.get(int(s[i]), -1) == -1:
			d[int(s[i])] = []
		d[int(s[i])].append(i)
	mini = 100
	for i in range(len(nums)):
		flag = True
		pos = -1
		for j in range(len(nums[i])):
			if d.get(int(nums[i][j]), -1) == -1:
				flag = False
				break
			else:
				ch = 0
				for j1 in range(len(d[int(nums[i][j])])):
					if d[int(nums[i][j])][j1] > pos:
						pos = d[int(nums[i][j])][j1]
						ch = 1
						break
				if ch == 0:
					flag = False
					break
		if flag:
			mini = min(len(s) - len(nums[i]), mini)
	if mini == 100:
		mini = -1
	return mini
for _ in range(t):
	n = int(input())
	print(solve())


import math
s = input()
n = len(s)
ans = -1
num = ''
for i in range(1, 1 << n):
	st = ''
	for j in range(n):
		if i >> j & 1:
			st += s[j]
	if st[0] != '0':
		temp = int(st)
		k = int(math.sqrt(temp))
		if k * k == temp:
			if ans < int(len(st)):
				ans = int(len(st))
				num = st
if ans == -1:
	print(ans)
else:
	print(n - ans)


import math
import itertools

def Solve(STR, s1):
	combs = []
	for l in range(1, len(STR) + 1):
		combs.append(list(itertools.combinations(STR, l)))
	flag = 0
	ans = 15
	for c in combs:
		for t in c:
			a = ''.join(t)
			if a[0] == '0':
				continue
			if int(a) in s1:
				ans = min(ans, len(STR) - len(a))
				flag = 1
	if flag == 1:
		print(ans)
	else:
		print(-1)
n = int(input())
n = str(n)
s1 = set()
i = 1
while i * i <= 2 * 10 ** 9:
	s1.add(i * i)
	i = i + 1
STR = ''.join(n)
Solve(STR, s1)


def is_square(n):
	if n < 0:
		return False
	if n == 0:
		return True
	(x, y) = (1, n)
	while x + 1 < y:
		mid = (x + y) // 2
		if mid ** 2 < n:
			x = mid
		else:
			y = mid
	return n == x ** 2 or n == (x + 1) ** 2
number = input()
total_steps = -1
substr_data = [(number, 0)]
used_str = set()
i = 0
while i < len(substr_data):
	if is_square(int(substr_data[i][0])):
		total_steps = substr_data[i][1]
		break
	if len(substr_data[i][0]) > 1:
		for c in range(len(substr_data[i][0])):
			substr = substr_data[i][0][:c] + substr_data[i][0][c + 1:]
			if substr[0] != '0' and substr not in used_str:
				substr_data.append((substr, substr_data[i][1] + 1))
				used_str.add(substr)
	i += 1
print(total_steps)


from collections import deque
(n, i, sq, f) = (int(input()), 1, set(), set())
while i ** 2 <= n:
	sq.add(i ** 2)
	i += 1
q = deque([(n, 0)])
while q:
	(c, v) = q.popleft()
	if c in sq:
		print(v)
		exit()
	s = str(c)
	for i in range(len(s)):
		s2 = s[:i] + s[i + 1:]
		if not s2 or s2[0] == '0':
			continue
		d = int(s2)
		if d not in f:
			f.add(d)
			q.append((d, v + 1))
print(-1)


num = input()
n = len(num)
myset = set([])
ans = n
for i in range(1, 50000):
	myset.add(str(i * i))
for mask in range(1, 1 << n):
	num2 = ''
	for i in range(n):
		if mask & 1 << i:
			num2 += num[i]
	num2 = num2.lstrip('0')
	if num2 != '' and num2 in myset:
		ans = min(ans, n - len(num2))
ans = -1 if ans == n else ans
print(ans)


def is_perfect_square(n):
	return round(n ** 0.5) ** 2 == n
from itertools import combinations
s = input()
ls = len(s)
sl = [i for i in s]
x = []
for i in range(1, len(s) + 1):
	comb = combinations(sl, i)
	for j in list(comb):
		x.append(list(j))
y = []
for i in x:
	a = ''
	for j in i:
		a += j
	y.append(int(a))
y = list(set(y))
y.sort(reverse=True)
f = 0
for i in y:
	if i != 0:
		if is_perfect_square(i):
			f = 1
			break
if f:
	print(ls - len(str(i)))
else:
	print(-1)


import math
a = input()
length = int(math.sqrt(int(a)) + 1)
squares = [str(x * x) for x in range(1, length)]
for square in reversed(squares):
	start_index = -1
	for square_char in list(square):
		start_index = a.find(square_char, start_index + 1)
		if start_index == -1:
			break
	else:
		print(str(len(a) - len(square)))
		exit()
print('-1')


n = input()
t = int(int(n) ** 0.5)
while t > 0:
	m = str(t * t)
	j = 0
	for i in range(len(n)):
		if n[i] == m[j]:
			j += 1
			if j == len(m):
				print(len(n) - j)
				exit()
	t -= 1
print('-1')


read_numbers = lambda : list(map(int, input().split()))
INF = 1 << 64
(x, ans) = (int(input()), INF)
xs = str(x)
for y in range(1, int(x ** 0.5) + 1):
	ys = str(y ** 2) + '#' * 10
	(l, r) = (0, len(ys) - 10)
	for i in xs:
		if ys[l] == i:
			l += 1
	if l >= r:
		ans = min(10 + len(xs) - len(ys), ans)
print(-1 if ans == INF else ans)


from math import *
t = input()
n = len(t)
m = 0
for i in range(2 ** n):
	j = i
	s = ''
	for k in range(n):
		if j % 2 == 1:
			s = t[n - 1 - k] + s
			j -= 1
		j = j // 2
	if s != '' and s[0] != '0':
		if round(sqrt(int(s))) * round(sqrt(int(s))) == int(s):
			if len(s) > m:
				m = len(s)
if m == 0:
	print(-1)
else:
	print(n - m)


import itertools
import math
n = input()
res = [seq for i in range(len(n), 0, -1) for seq in itertools.combinations(n, i) if math.sqrt(int(''.join(seq))).is_integer()]
if res == []:
	print(-1)
else:
	flag = 0
	for i in range(len(res)):
		if res[i][0] != '0':
			flag = 1
			print(len(n) - len(res[i]))
			break
	if flag == 0:
		print(-1)


s = input()
n = int(s)

def find(c, j):
	if j >= len(s):
		return -1
	while j < len(s):
		if c != s[j]:
			j += 1
		else:
			return j
	return -1

def isin(a):
	a = str(a)
	j = -1
	for i in range(len(a)):
		aa = a[i]
		j += 1
		j = find(aa, j)
		if j == -1:
			return False
	return True
i = 45000
ans = 0
found = False
while i > 0:
	ss = i ** 2
	if ss > n:
		i -= 1
		continue
	if isin(ss):
		ans = len(s) - len(str(ss))
		found = True
		break
	else:
		i -= 1
if found:
	print(ans)
else:
	print('-1')


import sys
import math

def check(a, b):
	a = str(a)
	b = str(b)
	l = len(b)
	t = 0
	for k in range(l):
		while True:
			if t > len(a) - 1:
				return False
			if a[t] != b[k]:
				t += 1
			else:
				t += 1
				break
	return True
n = int(input())
s = int(n ** 0.5)
m = 10 ** 10
for i in range(1, s + 1):
	if check(n, i * i):
		m = min(m, len(str(n)) - len(str(i * i)))
print(m if m < 10 ** 10 else '-1')


def assembly(n, array):
	if n in array or n == '' or n.find('0') == 0:
		return
	else:
		array.append(n)
	for i in range(len(n)):
		assembly(n[:i] + n[i + 1:], array)

def search(n, array):
	flag = True
	best = len(n) + 1
	assembly(n, array)
	for x in array:
		if int(x) ** 0.5 % 1 == 0:
			length = len(n) - len(x)
			if length < best:
				best = length
				flag = False
	if not flag:
		return best
	else:
		return -1
	return -1 if flag else best

def main():
	n = input()
	array = []
	print(search(n, array))
main()


num = input()
raiz = int(int(num) ** 0.5)
while raiz > 0:
	resposta = str(raiz ** 2)
	qtd = 0
	for i in range(len(num)):
		if num[i] == resposta[qtd]:
			qtd += 1
			if qtd == len(resposta):
				print(len(num) - qtd)
				exit()
	raiz -= 1
print(-1)


from math import sqrt

def is_square(n):
	r = int(sqrt(n))
	return r * r == n
n = input()
mx = 0
L = len(n)
for i in range(1 << L):
	s = ''
	for j in range(L):
		if i & 1 << L - j - 1:
			s += n[j]
	if s and s[0] != '0' and is_square(int(s)) and (len(s) > mx):
		mx = len(s)
print(L - mx if mx else -1)


from math import sqrt

def is_sqr(n: int) -> bool:
	s = int(sqrt(n))
	if s * s == n and n != 0:
		return True
	else:
		return False
number = int(input())
a = str(number)
n = len(a)
ans = -1
for mask in range(1, 1 << n):
	new_num = 0
	used = [False for i in range(n)]
	(ok, leftmost) = (True, False)
	for i in range(n):
		if mask & 1 << i:
			if a[i] == 0 and leftmost == True:
				ok = False
			leftmost = False
			used[i] = True
			new_num = new_num * 10 + int(a[i])
	if not is_sqr(new_num):
		continue
	if not ok:
		continue
	ans = max(ans, len(str(new_num)))
if ans == -1:
	print(-1)
else:
	print(n - ans)


n = input()
ans = 1000
ln = len(n)
for i in range(1, 2 ** ln):
	bn = str(bin(i))[2:]
	s = ''
	for j in range(len(bn)):
		if bn[j] == '1':
			s += n[j + (len(n) - len(bn))]
	if s[0] != '0':
		s = int(s)
		sqr = int(s ** 0.5)
		if sqr * sqr == s and i != 0:
			ans = min(ans, len(n) - bn.count('1'))
if ans == 1000:
	print(-1)
else:
	print(ans)


n = int(input())
s = str(n)
lst = []
t = set()

def xxx(string):
	if string[0] == '0':
		return
	x = int(string)
	if x in t:
		return
	t.add(x)
	k1 = 0
	k2 = 10 ** 6
	while k2 - k1 != 1:
		k = (k1 + k2) // 2
		if k ** 2 <= x:
			k1 = k
		else:
			k2 = k
	if k1 ** 2 == x:
		lst.append(len(str(x)))
	if len(string) == 1:
		return
	for x in range(len(string)):
		xxx(string[:x] + string[x + 1:])
	return
xxx(s)
if len(lst) == 0:
	print(-1)
else:
	print(len(s) - max(lst))


n = input()
(q, o) = (len(n), 11)
for i in range(1, int(int(n) ** 0.5) + 1):
	i = i ** 2
	(w, d, t, r) = (len(str(i)), str(i), 0, 0)
	for j in range(w):
		for k in range(r, q):
			if d[j] == n[k]:
				t += 1
				r = k + 1
				break
	if t == w:
		o = min(o, q - t)
print([-1, o][o != 11])


n = input()
(a, ans, l) = ([0] * 10, 100, len(str(n)))
if l == 10:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						for a[5] in range(2):
							for a[6] in range(2):
								for a[7] in range(2):
									for a[8] in range(2):
										for a[9] in range(2):
											s = ''
											for i in range(l):
												if a[i] == 0:
													s += n[i]
											if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
												ans = min(ans, a.count(1))
elif l == 9:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						for a[5] in range(2):
							for a[6] in range(2):
								for a[7] in range(2):
									for a[8] in range(2):
										s = ''
										for i in range(l):
											if a[i] == 0:
												s += n[i]
										if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
											ans = min(ans, a.count(1))
elif l == 8:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						for a[5] in range(2):
							for a[6] in range(2):
								for a[7] in range(2):
									s = ''
									for i in range(l):
										if a[i] == 0:
											s += n[i]
									if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
										ans = min(ans, a.count(1))
elif l == 7:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						for a[5] in range(2):
							for a[6] in range(2):
								s = ''
								for i in range(l):
									if a[i] == 0:
										s += n[i]
								if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
									ans = min(ans, a.count(1))
elif l == 6:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						for a[5] in range(2):
							s = ''
							for i in range(l):
								if a[i] == 0:
									s += n[i]
							if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
								ans = min(ans, a.count(1))
elif l == 5:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					for a[4] in range(2):
						s = ''
						for i in range(l):
							if a[i] == 0:
								s += n[i]
						if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
							ans = min(ans, a.count(1))
elif l == 4:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				for a[3] in range(2):
					s = ''
					for i in range(l):
						if a[i] == 0:
							s += n[i]
					if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
						ans = min(ans, a.count(1))
elif l == 3:
	for a[0] in range(2):
		for a[1] in range(2):
			for a[2] in range(2):
				s = ''
				for i in range(l):
					if a[i] == 0:
						s += n[i]
				if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
					ans = min(ans, a.count(1))
elif l == 2:
	for a[0] in range(2):
		for a[1] in range(2):
			s = ''
			for i in range(l):
				if a[i] == 0:
					s += n[i]
			if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
				ans = min(ans, a.count(1))
else:
	for a[0] in range(2):
		s = ''
		for i in range(l):
			if a[i] == 0:
				s += n[i]
		if s != '' and s[0] != '0' and (int(int(s) ** 0.5) ** 2 == int(s)):
			ans = min(ans, a.count(1))
if ans == 100:
	ans = -1
print(ans)


import math

def is_square(n):
	return math.sqrt(n).is_integer()
nums = set()
queue = []

def fill(num, d):
	if len(num) == 1:
		return -1
	for i in range(len(num)):
		if i == 0 and num[1] == '0':
			continue
		new_num = int(''.join(num[:i] + num[i + 1:]))
		if new_num not in nums:
			nums.add(new_num)
			queue.append((new_num, d))
sq = list(input())
if is_square(int(''.join(sq))):
	print(0)
else:
	fill(sq, 1)
	while len(queue) > 0:
		(num, d) = queue.pop(0)
		if is_square(num):
			print(d)
			break
		num = list(str(num))
		fill(num, d + 1)
	else:
		print(-1)


s = list(input())
ans = 10 ** 9
for i in range(1, 45001):
	sr = str(i * i)
	sri = 0
	for j in range(len(s)):
		try:
			if s[j] == sr[sri]:
				sri += 1
		except IndexError:
			pass
	y = len(s) - len(sr)
	if sri == len(sr):
		ans = min(ans, y)
ans = [ans, -1][ans == 10 ** 9]
print(ans)


from math import sqrt

def square(num, i, MAX):
	if not len(num):
		return float('inf')
	if i == MAX:
		if num[0] == '0':
			return float('inf')
		number = int(''.join(num))
		if int(sqrt(number)) ** 2 == number:
			return 0
		else:
			return float('inf')
	return min(square(num[:i] + num[i + 1:], i, MAX - 1) + 1, square(num, i + 1, MAX))
num = list(input())
MAX = len(num)
rslt = square(num, 0, MAX)
if rslt != float('inf'):
	print(rslt)
else:
	print(-1)


import math
s = set()
ans = int(2000000000.0 + 1)
n = input()
main = len(n)

def backtrack(x):
	global ans
	if len(x) <= 0:
		return
	x = int(x)
	if int(math.sqrt(x)) ** 2 == x:
		ans = min(ans, main - len(str(x)))
	s.add(x)
	x = str(x)
	if len(x) > 1:
		for i in range(1, len(x) + 1):
			news = x[:i - 1] + x[i:]
			if news not in s and news[0] != '0':
				backtrack(news)
	return
backtrack(n)
if ans == int(2000000000.0 + 1):
	print(-1)
else:
	print(ans)


import math
n = input()
m = len(n)
ans = m
for j in range(1, 2 ** m):
	cur = ''
	for i in range(m):
		if j >> i & 1:
			cur += n[i]
	if cur[0] == '0':
		continue
	cur = int(cur)
	var = int(math.sqrt(cur))
	if var ** 2 == cur:
		ans = min(ans, m - len(str(cur)))
if ans == m:
	print(-1)
else:
	print(ans)


arr = []

def m(a, ln):
	if len(a) == ln:
		arr.append(a)
		return
	m(a + '0', ln)
	m(a + '1', ln)

def main():
	a = input()
	m('', len(a))
	res = ''
	for i in range(len(arr)):
		b = ''
		for j in range(len(arr[i])):
			if arr[i][j] == '1':
				b += a[j]
		if not b or b[0] == '0':
			continue
		k = int(b)
		if k ** 0.5 == int(k ** 0.5) and len(b) > len(res):
			res = b
	if res:
		print(len(a) - len(res))
	else:
		print(-1)
main()


import itertools

def try_sqrt(n):
	m = int(n ** 0.5)
	return True if abs(m * m - n) < 1e-06 else False
N = int(input())
if try_sqrt(N):
	print(0)
	quit()
L = list(str(N))
for i in reversed(range(1, len(L))):
	for num_l in itertools.combinations(L, i):
		if num_l[0] == '0':
			continue
		num = int(''.join(num_l))
		if try_sqrt(num):
			print(len(L) - i)
			quit()
print(-1)


from math import sqrt
n = str(input())
w: int = []
for i in range(len(n)):
	w.append(int(n[i]) - int('0'))
x: int = len(n)
a: int = 0
t: int = x + 1

def proba(s: int, id: int, cnt: int):
	global x
	if id >= x:
		y = int(sqrt(s))
		global a, t
		if y * y == s and s > a:
			a = s
			t = cnt
		return
	proba(s, id + 1, cnt)
	proba(s * 10 + w[id], id + 1, cnt + 1)
proba(0, 0, 0)
print(x - t)


s = input()
import math

def rec(s, lis):
	new = []
	if len(lis) != 0 and len(lis[0]) == 1:
		return -1
	elif len(s) == 1:
		return -1
	elif len(lis) == 0:
		for i in range(len(s)):
			a = s[:i] + s[i + 1:]
			if math.sqrt(int(a)) - int(math.sqrt(int(a))) == 0 and a[0] != '0':
				return len(s) - len(a)
			new.append(a)
	else:
		for j in range(len(lis)):
			k = lis[j]
			for i in range(len(k)):
				a = k[:i] + k[i + 1:]
				if math.sqrt(int(a)) - int(math.sqrt(int(a))) == 0 and a[0] != '0':
					return len(s) - len(a)
				new.append(a)
	return rec(s, list(set(new)))
lis = []
if math.sqrt(int(s)) - int(math.sqrt(int(s))) == 0 and s[0] != '0':
	print(0)
else:
	ans = rec(s, lis)
	print(ans)


from math import sqrt, floor

def substr(s, t):
	j = 0
	for i in s:
		if j == len(t):
			return True
		if i == t[j]:
			j += 1
	return j == len(t)
s = input()
r = floor(sqrt(int(s)))
squares = [0] * r
for i in range(r, 0, -1):
	t = str(i ** 2)
	if substr(s, t):
		print(len(s) - len(t))
		exit()
print(-1)
exit()


x = input()
y = int(int(x) ** 0.5)
while y > 0:
	t = str(y ** 2)
	j = 0
	for i in range(len(x)):
		if x[i] == t[j]:
			j += 1
			if j == len(t):
				print(len(x) - j)
				exit()
	y -= 1
print(-1)


import math

def isSubString(str_s, str_t):
	i = 0
	j = 0
	while i < len(str_s) and j < len(str_t):
		if str_s[i] == str_t[j]:
			i += 1
			j += 1
		else:
			i += 1
	if j == len(str_t):
		return True
	return False
str_s = input()
for i in range(int(math.sqrt(int(str_s))), 0, -1):
	now = i ** 2
	if isSubString(str_s, str(now)):
		print(len(str_s) - len(str(now)))
		exit()
print(-1)


n = input()
n = ''.join(n)
s = []
for i in range(1, 100001):
	x = str(i ** 2)
	s.append(''.join(x))
ans = float('inf')
for i in s:
	if int(i) > int(n):
		break
	idx = 0
	for j in n:
		if idx == len(i):
			break
		if j == i[idx]:
			idx += 1
	if idx == len(i):
		ans = min(ans, len(n) - len(i))
if ans == float('inf'):
	print(-1)
else:
	print(ans)