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.*;
    import java.util.*;
  
 
  
        public class Codeforces {
    	
    		   public static long log2(long x)
    			{
    				long p=1;
    				long ans=0;
    				while(x>=p)
    				{
    					p*=2;
    					ans++;
    				}
    				return ans-1;
    			}
    		   
    		   
    		   public static void extendedgcd(int a, int b)
    		   {
    			   x=0;
    			   y=0;
    			   gc=0;
    			   xgcd(a,b);
    			   pw.println(a+"*"+x+" + "+b+"*"+y+" = "+gc);
    			   
    		   }
    		   
    		   
    		   public static long modex(long a, long b, long c)
    		   {
    			   if(b==0)
    				   return 1;
    			   else if(b==1)
    				   return a%c;
    			   else if(b%2==0)
    			   {
    				   	return modex((a*a)%c,b/2,c);
    			   }
    			   else
    			   {
    				   return (a*modex((a*a)%c,b/2,c))%c;
    				   
    			   }
    			   
    			   
    		   }
    		   
    		   
    		   public static void xgcd(int a, int b)
    		   {
    			   
    			   if(b==0)
    			   {
    				   x=1;
    				   y=0;
    				   gc=a;
    				   
    				   
    			   }
    			   else
    			   {
    				   xgcd(b,a%b);
    				   int temp = x;
    				   x=y;
    				   y = temp - ((a/b)*y);
    				   
    			   }
    		   }
    		   
    		   public static long gcd(long a, long b)
    		   {
    			   if(b==0)return a;
    			   else return gcd(b,a%b);
    			   
    		   }
    		   
    		   static int x,y,gc;
    		   
    		  
    		
    		   
    		   static HashSet<Character> set;
    		   
    		   
    		   
    		   public static long expmod(long a, long b, long mod)
    		   {
    			   if(b==0)return 1;
    			   if(b==1)return a;
    			   
    			   if(b%2==0)
    			   {
    				   return ((expmod(a,b/2,mod)%mod)*(expmod(a,b/2,mod)%mod))%mod;
    			   }
    			   else
    			   {
    				   return ((a%mod)*(expmod(a,b/2,mod)%mod)*(expmod(a,b/2,mod)%mod))%mod;
    			   }
    		   }
    		   
    		   static class Comp implements Comparator<Point>
    		   {

				@Override
				public int compare(Point arg0, Point arg1) {
					
					if(arg0.x>arg1.x)return 1;
					if(arg0.x<arg1.x)return -1;
					return 0;
				}
    			   
    		   }
    		   
    		   
    		   static class STComp implements Comparator<Integer>
    		   {

				@Override
				public int compare(Integer arg0, Integer arg1) {
					
					return arg0.compareTo(arg1); 
				}
    			   
    		   }
    		   
    		   static class Point
    		   {
    			   int x,y,ind;
    			   
    			    public Point(int a, int b)
    			    {
    			    	x=a;
    			    	y=b;
    			    	ind=0;
    			    }
    			   
    			    
    		   }
    		   
    		 
    		   
    		  
    		   
    		   public static boolean issub(String s1, String s2)
    		   {
    			   if(s1.length()>s2.length())
    			   return false;
    			   
    			   int l1 = s1.length();
    			   int l2 = s2.length();
    			   
    			   
    			   for(int i=0;i<=l2-l1;i++)
    			   {
    				   String sub = s2.substring(i, i+l1);
    				   if(s1.equals(sub))return true;
    			   }
    			   
    			   return false;
    		   }
    		   
    		   
    		   
    		   public static String enc(String s, int n)
    		   {
    			   String s1 = s.substring(0,n);
    			   String s2 = s.substring(n, s.length());
    			   
    			  String re="";
    			  for(int i=s1.length()-1;i>=0;i--)re+=s1.charAt(i);
    			  
    			  return re+s2;
    			   
    			   
    			   
    		   }
    		 
    		   
    		   
    		   static int vis[];
    		   
    		   public static void dfs(int x)
    		   {
    			   vis[x]=1;
    			   
    			   ArrayList<Integer> li = adj[x];
    			   
    			   for(int ch:li)
    			   {
    				   
    				   if(vis[ch]==0)dfs(ch);
    				   
    			   }
    			   
    		   }
    		   /*
    		   public static void dfsm(int x, HashSet<Integer> set)
    		   {
    			   vis2[x]=1;
    			   
    			   ArrayList<Integer> li = adj[x];
    			   
    			   for(int ch:li)
    			   {
    				   //if(!set.contains(ch))continue;
    				   if(vis2[ch]==0)dfsm(ch,set);
    				   
    			   }
    			   
    		   }
    		   */
    		   
    		  
    		
    		   public static void countPaths(int s, int d, ArrayList<Integer> pa)
    		   {
    			   
    			   vis2[s]=1;
    			   if(s==d)
    			   {
    				   pa.add(s);
    				 //  paths[ct] = new ArrayList<Integer>(pa);
    				   ct++;
    			   }
    			   else
    			   {
    				   ArrayList<Integer> li = adj[s];
    				   pa.add(s);
    				   
    				   for(int ad: li)
    				   {
    					   if(vis2[ad]==0)countPaths(ad,d,pa);
    				   }
    				   
    				   
    			   }
    			   
    			   if(pa.size()>1)pa.remove(pa.size()-1);
    			   vis2[s]=0;
    			   return ;
    		   }
    		  
    		   
    		   
    		   public static boolean dif(String s1, String s2)
    		   {
    			   int ct=0;
    			   if(s1.length()!=s2.length())return false;
    			   for(int i=0;i<s1.length();i++)
    			   {
    				   if(s1.charAt(i)!=s2.charAt(i))ct++;
    				   
    			   }
    			   
    			   if(ct==1)return true;
    			   else return false;
    			   
    			   
    		   }
    		   
    		   
    		   
    		   
    		   static void add(int arr[], int N, int lo,
                       int hi, int val)
    		   {
							    arr[lo] += val;
							    if (hi != N - 1)
							       arr[hi + 1] -= val;
    		   }
 
// Utility method to get actual array from 
// operation array
static void updateArray(int arr[], int N)
{
    // convert array into prefix sum array
    for (int i = 1; i < N; i++)
        arr[i] += arr[i - 1];
}
  
// method to print final updated array
static void printArr(int arr[], int N)
{
    updateArray(arr, N);
    for (int i = 0; i < N; i++)
        System.out.print(""+arr[i]+" ");
    System.out.print("\n");
}
  
    		   
    		   

	static  ArrayList<Integer>[] adj;
	static int[] vis2;
	static int ct;

    		   
    		  static int cyc;
    		   
    		   
    		  
    		  public static void dfsmod(int v, HashSet<Integer> set)
    		  {
    			  vis2[v]=1;
    			  
    			  ArrayList<Integer> li = adj[v];
    			  
    			  set.add(v);
    			  
    			  for(int ch: li)
    			  {
    				  if(set.contains(ch))
    				  {
    					  cyc=1;
    					  pw.println("** "+ch+" "+v);
    				  }
    				  if(vis2[ch]==0)dfsmod(ch,set);
    				  
    			  }
    			  
    			  set.remove(v);
    			  
    			  
    		  }
    		  
    		  
    		  	public static boolean isps(int x)
    		  	{
    		  		int sq = (int)Math.sqrt(x);
    		  		
    		  		return sq>0&&sq*sq==x;
    		  		
    		  		
    		  		
    		  		
    		  		
    		  		
    		  		
    		  		
    		  		
    		  	}
    		  
    		  	 public static void combinations(String suffix,String prefix){
    		         if(prefix.length()<0)return;
    		         else
    		         {
    		        	 if(!st.contains(suffix))
    		        	 {
    		        		 poss[ctr++]=suffix;
    		        		 st.add(suffix);
    		        	 }
    		        	 
    		        	 
    		         for(int i=0;i<prefix.length();i++)
    		          combinations(suffix+prefix.charAt(i),prefix.substring(i+1,prefix.length()));
    		         }
    		     }
    		  	
    		  	
    		  	 
    		  	 static int alen;
    		  	 static String[] poss;
    		  	 static HashSet<String> st;
    		  	 static int ctr;
    		   
    		  	 
    		  	 public static boolean isprop(String x)
    		  	 {
    		  		 
    		  		 if(x.length()>1&&x.charAt(0)=='0')return false;
    		  		 else return true;
    		  	 }
    		  	 
    		  	 
    		  	 public static void main(String[] args) 
    	   {
    			   ctr=0;
    			 int n = sc.nextInt();
    			 poss = new String[1024];
    			 st = new HashSet<String>();
    			 String nst = Integer.toString(n);
    			 int dg = nst.length();
    			 
    			 alen = Integer.MIN_VALUE;
    			 combinations("",nst);
    			 
    			for(int i=0;i<ctr;i++)
    			{
    				String p = poss[i];
    				//pw.println("** "+p);
    				if(p.length()>0&&isprop(p)&&isps(Integer.parseInt(p))&&p.length()>alen)
    				{
    					alen=p.length();
    				}
    				
    				
    			}
    			
    			if(alen==Integer.MIN_VALUE)
    			{
    				pw.println(-1);
    			}
    			else
    			pw.println(dg-alen);
    			   /*  
    			  cyc=0;
       			adj = new ArrayList[4];
       			vis2 = new int[4];
       			
       			for(int i=0;i<4;i++)adj[i] = new ArrayList<Integer>();
       			   
       			
       			adj[0].add(1);
       			adj[0].add(2);
       			adj[0].add(3);
       			
       			adj[1].add(3);
       			
       			//adj[2].add(0);
       			adj[2].add(1);
    			   adj[3].add(2);
    			   
       			HashSet<Integer> empty = new HashSet<Integer>();
       			
       			
       			for(int i=0;i<4;i++)
       			{
       				if(vis2[i]==0)dfsmod(i,empty);
       			}
    			   
    			pw.println(cyc);
    			*/
    			   
    			/*
    			int n = sc.nextInt();
    			
    			int arr[] = new int[n];
    			
    			for(int i=0;i<n;i++)arr[i]=sc.nextInt();
    			
    			long ansg =0,ansv = Long.MAX_VALUE; 
    			
    			int arr2[] = new int[n];
    			for(int i=0;i<n;i++)arr2[i]=arr[i]-i;
    		
    			for(int i=0;i<n;i++)
    			{
    				int x = arr2[i];
    				
    				if(x<=0)
    				{
    					
    					if(i<ansv)
    					{
    						
    						ansg=i;
    						ansv=i;
    					}
    				}
    				else
    				{
    					float t = ((float)x)/n;
    					long tt = (long)Math.ceil(t);
    					
    					long ex = i;
    					long ti = tt*n+ex;
    					
    					
    					if(ti<ansv)
    					{
    						//pw.println("** "+i);
    						ansg=i;
    						ansv=ti;
    					}
    					
    				}
    				
    				
    				
    			}
    			
    			pw.println(ansg+1);
    			*/
    			   
    			   
    			   
    		
    			   
    			   
    	
    			   
    			   /*ct=0;
    			
    			paths= new ArrayList[10];
    			adj = new ArrayList[4];
    			vis2 = new int[4];
    			
    			for(int i=0;i<4;i++)adj[i] = new ArrayList<Integer>();
    			   
    			for(int i=0;i<10;i++)paths[i] = new ArrayList<Integer>();
    			
    			adj[0].add(1);
    			adj[0].add(2);
    			adj[0].add(3);
    			
    			adj[1].add(3);
    			
    			adj[2].add(0);
    			adj[2].add(1);
    			
    			countPaths(2,3, new ArrayList<Integer>());
    			pw.println(ct);
    			   
    			for(int i=0;i<ct;i++)pw.println(paths[i]);
    			  */ 
    			   
    			   
    			   
    			   /*
    			   int n = sc.nextInt();
    			int m = sc.nextInt();
    			
    			int arr[] = new int[n];
    			
    			for(int i=0;i<n;i++)arr[i]=sc.nextInt();
    			
    			int req = n/m;
    			
    			int[] rem = new int[m];
    			
    			
    			HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
    			for(int i=0;i<n;i++)
    			{
    				rem[arr[i]%m]++;
    				
    			}
    			int li=-1;
    			long ans=0;
    			for(int i=0;i<m;i++)
    			{
    				if(rem[i]>=req)
    				{
    					rem[(i+1)%m]+=rem[i]-req;
    					ans+=(rem[i]-req);
    				}
    				else
    				{
    					li=i;
    					
    				}
    			}
    			
    			for(int i=0;i<li;i++)
    			{
    				if(rem[i]>=req)
    				{
    					rem[(i+1)%m]+=rem[i]-req;
    					ans+=(rem[i]-req);
    				}
    				else
    				{
    					li=i;
    					
    				}
    			}
    			pw.println(ans);
    			*/
    			
    			
    			
    			   //pw.println(pa);
    		/*	  NGE 
       		int[] sto = {100,80,60,70,60,75,85};
       		int n = sto.length;
       		
       		int[] spa = new int[n];
       		spa[0]=1;
       		
       		Stack<Integer> st = new Stack<Integer>();
       		st.push(0);
       		
       		for(int i=1;i<n;i++)
       		{
       			
       			while(!st.isEmpty()&&sto[st.peek()]<=sto[i])st.pop();
       			
       			spa[i]=(st.isEmpty())?i+1:i-st.peek();
       			st.push(i);
       			
       		}
    			  
       		
       		for(int i=0;i<n;i++)pw.print(sto[i]+" ");
    			   pw.println();
    			   for(int i=0;i<n;i++)pw.print(spa[i]+" ");
    			  
    			   
    			   int[] nge = new int[n];
    			   
    			   st.clear();
    			   Stack<Point> st2 = new Stack<Point>();
    			   st2.push(new Point(sto[0],0));
    			   
    			   for(int i=1;i<n;i++)
    			   {
    				   while(!st2.isEmpty()&&st2.peek().x<sto[i])
    				   {
    					   Point pop = st2.pop();
    					   nge[pop.y]=sto[i];
    				   }
    				   st2.push(new Point(sto[i],i));
    				   
    			   }
    			   
    			   while(!st2.isEmpty())
    			   {
    				   nge[st2.pop().y]=-1;
    			   }
    			  
    			   pw.println();
    			   for(int i=0;i<n;i++)pw.print(sto[i]+" ");
    			   pw.println();
    			   for(int i=0;i<n;i++)pw.print(nge[i]+" ");
    			 */ 
    			   
    			   /*  int r = 2000000000;
    			  pw.println(r);
    			int n = sc.nextInt();
    			int k = sc.nextInt();
    			int l = sc.nextInt();
    			int m = n*k;
    			int arr[] = new int[m];
    			
    			for(int i=0;i<m;i++)arr[i]=sc.nextInt();
    			
    			Arrays.sort(arr);
    			
    			int limit = l+arr[0];
    			int li=-1;
    			
    			for(int i=0;i<m;i++)
    			{
    				//pw.println(arr[i]);
    				if(arr[i]>limit)
    				{
    					//pw.println(arr[i]);
    					li=i; break;
    				}
    			}
    			//pw.println(limit+" "+li);
    			if(li==-1)li=n;
    			
    			int noofsmallest = li;
    			
    			if(noofsmallest<n)
    			{
    				pw.println(0);
    			}
    			else
    			{
    				li--;
    				long ans=0;
    				for(int i=0;i<n-1;i++)
    				{
    					ans+=(long)arr[li];
    					li--;
    				}
    				ans+=arr[0];
    				pw.println(ans);
    				
    			}
    			  */ 
    			   
    			   
    			   
    		
    			 
    			  
    			pw.close();  
    			   
    	   }
    		   
    		   
    		   
    		   static  class MyScanner 
    			{
    	
    			BufferedReader br;
    			StringTokenizer st;
    	
    			public MyScanner() 
    			{
    				br = new BufferedReader(new InputStreamReader(System.in));
    			}
    	
    			String next() 
    			{
    				
    				while (st == null || !st.hasMoreElements()) 
    				{
    					try 
    					{
    						st = new StringTokenizer(br.readLine());
    					} catch (IOException e) 
    					{
    						e.printStackTrace();
    					}
    				}
    				return st.nextToken();
    			}
    	
    			int nextInt() 
    			{
    				return Integer.parseInt(next());
    			}
    	
    			long nextLong() 
    			{
    				return Long.parseLong(next());
    			}
    	
    			double nextDouble() 
    			{
    				return Double.parseDouble(next());
    			}
    	
    			String nextLine()
    			{
    				String str = "";
    				try 
    				{
    					str = br.readLine();
    				} catch (IOException e) 
    				{
    					e.printStackTrace();
    				}
    				return str;
    			}
    	
    		}
    	
    		static MyScanner sc = new  MyScanner();
    		static PrintWriter pw = new PrintWriter(System.out, true);
    		
    	
    	
    		
    	}  