#include <bits/stdc++.h>
using namespace std;
long long fast_pow(long long a, long long p) {
  long long res = 1;
  while (p) {
    if (p % 2 == 0) {
      a = a * 1LL * a % 998244353;
      p /= 2;
    } else {
      res = res * 1LL * a % 998244353;
      p--;
    }
  }
  return res;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 1; i <= n; i++) {
    res = res * 1LL * i % 1000000007;
  }
  return res;
}
long long C(long long n, long long k) {
  return fact(n) * 1LL * fast_pow(fact(k), 1000000007 - 2) % 1000000007 * 1LL *
         fast_pow(fact(n - k), 1000000007 - 2) % 1000000007;
}
vector<long long> sieveOfEratosthenes(long long n) {
  vector<long long> primes;
  vector<bool> prime(n + 1, true);
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long p = 2; p <= n; p++)
    if (prime[p]) primes.push_back(p);
  return primes;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
bool isPerfectSquare(long double x) {
  if (x >= 0) {
    long long sr = sqrt(x);
    return (sr * sr == x);
  }
  return false;
}
long long sum(long long n) {
  long long res = 0;
  while (n > 0) {
    res += n % 10;
    n = n / 10;
  }
  return res;
}
vector<long long> adj[10001];
vector<long long> vis(10001);
vector<long long> col(10001);
void dfs(long long v) {
  vis[v] = 1;
  for (auto ch : adj[v]) {
    if (vis[ch] == 0) {
      dfs(ch);
    }
  }
}
bool bptdfs(long long v, long long c) {
  vis[v] = 1;
  col[v] = c;
  for (auto ch : adj[v]) {
    if (vis[ch] == 0) {
      if (bptdfs(ch, c ^ 1) == false) {
        return false;
      }
    } else {
      if (col[v] == col[ch]) {
        return false;
      }
    }
  }
  return true;
}
unordered_set<string> st;
void subsequence(string str) {
  for (long long i = 0; i < str.length(); i++) {
    for (long long j = str.length(); j > i; j--) {
      string sub_str = str.substr(i, j);
      st.insert(sub_str);
      for (long long k = 1; k < sub_str.length() - 1; k++) {
        string sb = sub_str;
        sb.erase(sb.begin() + k);
        subsequence(sb);
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long ans = 1000000007;
    bool ok = false;
    string s = to_string(n);
    long long k = s.length();
    subsequence(s);
    for (auto i : st) {
      long long x = stoi(i);
      long long l = i.length();
      if (isPerfectSquare(x) and i[0] != '0') {
        ok = true;
        long long v = k - l;
        ans = min(ans, v);
      }
    }
    if (!ok) {
      cout << "-1";
      continue;
    } else {
      cout << ans;
    }
  }
}
