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

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

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

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

Input

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

Output

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

Examples

Input

8314


Output

2


Input

625


Output

0


Input

333


Output

-1

Note

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

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

In the third example it is impossible to make the square from 333, so the answer is -1.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class C {
	static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
	static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

	public static int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	public static String next() throws IOException {
		in.nextToken();
		return (String) in.sval;
	}
	
	static boolean dis[] = new boolean[13];
	static HashSet<String> st = new HashSet<>();
	static int min;
	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		String s = input.next();
		
		int n = s.length();
		int max = -1;
		subsequence(s);
		
		for (String ss : st) {
			StringBuffer b = new StringBuffer(ss);
			for(int i = 0; i < b.length(); i++) {
				if(b.charAt(i) == '0' && b.length() > 1) {
					b.delete(i, i + 1);
					i--;
				}else {
					break;
				}
			}
			
			double d1 = Math.sqrt(Double.parseDouble(b.toString()));
			int d2 = (int)d1;
			if(d1 == d2 && d1 != 0) {
				max = Math.max(max, b.length());
			}
		}
		out.println(max == -1 ? -1 : n - max);
		out.flush();
		input.close();
	}
	
	
	public static void subsequence(String str) {  // 获取的可能性、
		for(int i = 0;i < str.length(); i++) {
			for(int j = str.length(); j > i; j--) {
				String sub_str = str.substring(i, j);
				if(!st.contains(sub_str)) { // 子字符串不在里面、
					st.add(sub_str);
				}
				
				for(int k = 1; k < sub_str.length() - 1; k++) {
					StringBuffer sb = new StringBuffer(sub_str);
					
					sb.deleteCharAt(k);
					if(!st.contains(sb)) {
						subsequence(sb.toString());
					}
				}
			}
		}
	}

}
