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.
//package com.company;
import com.sun.nio.sctp.SctpStandardSocketOptions;

import javax.swing.*;
import java.util.Calendar;
import java.net.StandardSocketOptions;
import java.util.*;
import java.util.Calendar;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Random;
import java.util.StringTokenizer;
import java.io.*;
import java.util.ArrayList;
/*
						            	    DOMINGO_GIRL :)
											─────────▄──────────────▄
											────────▌▒█───────────▄▀▒▌
											────────▌▒▒▀▄───────▄▀▒▒▒▐
											───────▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐
											─────▄▄▀▒▒▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐
											───▄▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀██▀▒▌
											──▐▒▒▒▄▄▄▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄▒▒▌
											──▌▒▒▐▄█▀▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐
											─▐▒▒▒▒▒▒▒▒▒▒▒▌██▀▒▒▒▒▒▒▒▒▀▄▌
											─▌▒▀▄██▄▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
											─▌▀▐▄█▄█▌▄▒▀▒▒▒▒▒▒░░░░░░▒▒▒▐ Wow
											▐▒▀▐▀▐▀▒▒▄▄▒▄▒▒▒▒▒░░░░░░▒▒▒▒▌
										   	▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒░░░░░░▒▒▒▐
											─▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒▒▒░░░░▒▒▒▒▌
											─▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
											──▀▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▌
											────▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀
											───▐▀▒▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀
											──▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▀
                                    	*/

public class Main {
    static HashSet<String> st = new HashSet<>();
    static HashSet<Integer> st2 = new HashSet<>();
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();
        subsequence(Long.toString(n));
        int a[]=new int[st.size()];
        Iterator<String> itr = st.iterator();
        for(int i=0;itr.hasNext();i++){
            a[i]=Integer.valueOf(itr.next());
        }
        //System.out.println(Arrays.toString(a));

        for(int i=0;i<a.length;i++){
            int sqrt=(int)Math.sqrt(a[i]);
            if(sqrt*sqrt==a[i]&&a[i]!=0){
                st2.add(a[i]);
            }
        }
      // System.out.println(st2);
        // System.out.println(obj);
       if(st2.size()==0)System.out.println(-1);
       else{
           Integer o = Collections.max(st2);
           String r=Integer.toString(o);
           String r2=Long.toString(n);
           System.out.println(r2.length()-r.length());
       }
    }

    static void subsequence(String str)
    {
        // iterate over the entire string
        for (int i = 0; i < str.length(); i++) {

            // iterate from the end of the string
            // to generate substrings
            for (int j = str.length(); j > i; j--) {
                String sub_str = str.substring(i, j);

                if (!st.contains(sub_str))
                    st.add(sub_str);

                // drop kth character in the substring
                // and if its not in the set then recur
                for (int k = 1; k < sub_str.length() - 1; k++) {
                    StringBuffer sb = new StringBuffer(sub_str);

                    // drop character from the string
                    sb.deleteCharAt(k);
                    if (!st.contains(sb))
                        ;
                    subsequence(sb.toString());
                }
            }
        }
    }
    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    // method to return LCM of two numbers
    static long lcm(long a, long b)
    {
        return (a*b)/gcd(a, b);
    }
    static class pair implements Comparable<pair> {
        int idx;
        int value;

        pair(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }

        @Override
        public int compareTo(pair o) {
            return o.value - this.value;
        }
    }


    static void move(int a[],int idx){
        int t=a[idx];
        for(int i=idx;i>0;i--){
            a[i]=a[i-1];
        }
        a[0]=t;
    }
    static int findIndex(int[] a, int item)
    {
        for(int i = 0; i < a.length; ++i)
            if(item == a[i])
                return i;
        return -1;
    }
    static boolean isPal(char[] s) {
        for (int i = 0; i < s.length / 2; i++)
            if (s[i] != s[s.length - i - 1])
                return false;
        return true;
    }
    static String get(int sec) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, sec);
        return new SimpleDateFormat("HH:mm:ss").format(calendar.getTime());

    }
    static class Pair  {
        int idx;
        int first, second;

        Pair(int a, int b, int c) {
            first = a;
            second = b;
            idx = c;
        }

    }

    //System.out.println(s);
    //pw.println(s);

/*
    static void moveT(int []a,int idx){
        int t=a[idx];
        for(int i=idx;i>0;i--){
            a[i]=a[i-1];
        }
        a[0]=t;
    }
    static int findIndex(int[] a, int item)
    {
        for(int i = 0; i < a.length; ++i)
            if(item == a[i])
                return i;
        return -1;
    }
    static class pair implements Comparable<pair>{
        int idx;
        int value;

        pair(int idx,int value){
            this.idx=idx;
            this.value=value;
        }

        @Override
        public int compareTo(pair o) {
            return o.value-this.value;
        }
    }

*/


    //Equilibrium index of an array is an index such that the sum of elements
    // at lower indexes is equal to the sum of elements at higher indexes.

    int equilibrium(int arr[], int n)
    {
        int sum = 0; // initialize sum of whole array
        int leftsum = 0; // initialize leftsum

        /* Find sum of the whole array */
        for (int i = 0; i < n; ++i)
            sum += arr[i];

        for (int i = 0; i < n; ++i) {
            sum -= arr[i]; // sum is now right sum for index i

            if (leftsum == sum)
                return i;

            leftsum += arr[i];
        }

        /* If no equilibrium index found, then return 0 */
        return -1;
    }


    static int LCSubStr(char X[], char Y[], int m, int n)
    {
        // Create a table to store lengths of longest common suffixes of
        // substrings. Note that LCSuff[i][j] contains length of longest
        // common suffix of X[0..i-1] and Y[0..j-1]. The first row and
        // first column entries have no logical meaning, they are used only
        // for simplicity of program
        int LCStuff[][] = new int[m + 1][n + 1];
        int result = 0;  // To store length of the longest common substring

        // Following steps build LCSuff[m+1][n+1] in bottom up fashion
        for (int i = 0; i <= m; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                if (i == 0 || j == 0)
                    LCStuff[i][j] = 0;
                else if (X[i - 1] == Y[j - 1])
                {
                    LCStuff[i][j] = LCStuff[i - 1][j - 1] + 1;
                    result = Integer.max(result, LCStuff[i][j]);
                }
                else
                    LCStuff[i][j] = 0;
            }
        }
        return result;
    }



}