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.math.*;
import java.text.*;
import java.util.*;
import java.lang.*;


public class Contest1 {
	//static ArrayList<Integer> prime=new ArrayList();
	
	   public static TreeMap<Long,Integer> t1=new TreeMap();
	   public static void solve()
	    {
	      long m=1;
	      for(int j=2;j<=1000;j++)
	      {
	         
	          if(isprime(j))
	          {
	              m=m*j;
	              if(m>1000000)
	              {
	                  break;
	              }else{
	                  t1.put(m,1);
	              }
	          }
	      }
	    }
	
    public static int gcd(int n1, int n2)
    {
        if (n2 != 0)
            return gcd(n2, n1 % n2);
        else
            return n1;
    }
	
//////////////////	
	public static class trie {
        int x,y,z;
        trie (int x,int y,int z){
            this.x=x;
            this.y=y;
            this.z=z;
        }
	
	} 
        
	public static class pair {
        int x,y;
        pair (int x,int y){
            this.x=x;
            this.y=y;
        }
        public boolean equals(Object o) {
        	if(o instanceof pair) {
        		pair p = (pair)o;
        		return (x == p.x && y == p.y);
        	}
        	return false;
        }
        public int hashCode() {
        	return (Integer.hashCode(x) * 3 + Integer.hashCode(y) );
        }
    }
	
//////////////////	
	
	static class Cmp implements Comparator<pair>
	{
		public int compare(pair a,pair b)
		{
			if(a.x==b.x)
			{
				return(a.y-b.y);
			}
			return(a.x-b.x);
		}
	}
	
	
//////////////////
	
	
	
	
//////////////////
	
	
	
	
	
	   static class FastReader
	   {
		   BufferedReader br;
		   StringTokenizer st;
		   public FastReader()
		   {
			   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; 
	        } 
	   }
	   
////////////////////// 
	//public static ArrayList<Integer> a=new ArrayList();
	   
	  public static ArrayList<Integer> Divisors(int n) 
	  { 
	       // Note that this loop runs till square root 
		  ArrayList<Integer> a=new ArrayList();
		   long sum=0;
	       for (int i=1; i*i<=(n); i++) 
	       { 
	           if (n%i == 0) 
	           { 
	               // If divisors are equal, print only one 
	               if (n/i == i) 
	               {
	                  // printf("%d ", i); 
	            	   sum=sum+1;
	            	   a.add(i);
	               }
	     
	               else // Otherwise print both 
	               {
	                   //printf("%d %d ", i, n/i); 
	            	   sum=sum+2;
	            	   a.add(i);
	            	   a.add(n/i);
	               }
	           } 
	       } 
	       return(a);
	   } 
	   
/////////////////////	  
	  
	  public static long SmallestPrimeDivisor(long n) 
	  { 
	      // if divisible by 2 
	      if (n % 2 == 0) 
	          return 2; 
	    
	      // iterate from 3 to sqrt(n) 
	      for (long i = 3; i * i <= n; i += 2) { 
	          if (n % i == 0) 
	              return i; 
	      } 
	    
	      return n; 
	  } 
	    
////////////////////	  
	   
	   public static boolean isprime(long n)
	    {
	        int count=0;
	     
	        for(long i=2;i*i<=n;i++)
	        {
	            if(n%i==0)
	            {
	                return(false);
	            }
	        }
	        return(true);
	    }
	
	   
//////////////////////
	   
	     //   (x^n)%1000000007
	   public static long modularExponentiation(long x,long n,long M)
	   {
	       if(n==0)
	           return 1;
	       else if(n%2 == 0)        //n is even
	           return modularExponentiation((x*x)%M,n/2,M);
	       else                             //n is odd
	           return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

	   }
	   
	   public static long nCr(int n,int k)
	   {
		  if(k==0)
			  return 1;
		  return(n*nCr(n-1,k-1)/k);
	   }
	   public static long factorial(int n)
	   {
		   if(n==1)
			   return 1;
		   return((n)*factorial(n-1));
	   }
	   
	   public static void debug(Object...o) {
		    System.out.println( Arrays.deepToString(o) );
	   }
	   
	   public static boolean prime[]=new boolean[100005];
	   //prime[j]==false means it's a prime.
	   public static void seive()
	   {
		   prime[0]=false;
		   prime[1]=false;
		   for(int i=2;i*i<=100005;i++)
		   {
			   if(!prime[i])
			   {
				   for(int j=i*i;i<=100005;j+=i)
				   {
					   prime[j]=true;
				   }
			   }
		   }
	   }
	 
	 
	    public static boolean equals(StringBuilder sb1, StringBuilder sb2){
	    
	        if(sb1 == sb2)
	  
	        if(sb1 == null || sb2 == null)
	            return false;
	        
	        boolean isEqual = true;
	  
	        if(sb1.length() == sb2.length()){
	  
	            for(int i = 0 ; i < sb1.length(); i++){
	                
	                if(sb1.charAt(i) != sb2.charAt(i)){
	                    isEqual = false;
	                    break;
	                }
	            }
	            
	        }else{
	            isEqual = false;
	        }
	        
	        return isEqual;
	    }
	   
	    
	    public static boolean IsPalindrome(String s,int n)
	    {
	    	
	    	for(int i=0;i<n/2;i++)
	    	{
	    		if(s.charAt(i)!=s.charAt(n-i-1))
	    		{
	    			return false;
	    		}
	    	}
	    	return true;
	    }
	   
	   
	    
	    static long findSubarraySum(int arr[], int n, long sum)  
	    { 
	        HashMap <Long, Integer> prevSum = new HashMap<>(); 
	        HashMap <Long ,Integer> index=new HashMap();
	        
	        long res = 0;  
	        
	        // Sum of elements so far.  
	        long currsum = 0;  
	        
	        for (int i = 0; i < n; i++) {  
	        
	            // Add current element to sum so far.  
	            currsum += arr[i];  
	            if (currsum == sum)   
	                res++;          
	        
	           
	            if (prevSum.containsKey(currsum - sum))   
	                res += prevSum.get(currsum - sum);  
	                
	         
	            Integer count = prevSum.get(currsum); 
	            if (count == null) 
	            {
	                prevSum.put(currsum, 1); 
	                index.put(currsum,i);
	            }
	                
	            else
	            {
	                prevSum.put(currsum, count+1); 
	            }
	        }  
	        
	        return res;  
	    }  
	      
	  
	    public static  ArrayList<String> AllSubSeq = new ArrayList();
	       // String ans = ""; (Initially)
	       public static void AllSubSequence(String s,String ans)
	       {
	    	   if(s.length()==0)
	    	   {
	    		   AllSubSeq.add(ans);
	    		   return ; 
	    	   }
	    	   AllSubSequence(s.substring(1), ans + s.charAt(0));
	    	   AllSubSequence(s.substring(1),ans);
	    	   
	    	   
	       }

	    
	    
	  public static void main(String args[])
	  {
		  //Scanner sc=new Scanner(System.in);
		  FastReader in = new FastReader();
		  PrintWriter pw = new PrintWriter(System.out);
		
		  int n=in.nextInt();
		  String s= Integer.toString(n);
		  int len = s.length();
		  AllSubSequence(s,"");
		  int size  = AllSubSeq.size();
		  int min = Integer.MAX_VALUE;
		  for(int i=0;i<size-1;i++)
		  {
			  if(AllSubSeq.get(i).charAt(0)!='0')
			  {
			  int y = Integer.parseInt( AllSubSeq.get(i) );
			  int z =(int) Math.sqrt(y);
			  if(z*z == y )
			  {
				  int x = len - AllSubSeq.get(i).length();
				  if(x<min)
				  {
					  min=x;
				  }
			  }
			  }
		  }
		  if(min==Integer.MAX_VALUE)
		  {
			  pw.println(-1);
		  }
		  else
		  {
			  pw.println(min);
		  }
		  
		  pw.flush();
		  pw.close();
	  }
	    
	    
	
}
			
