#include <bits/stdc++.h>
using namespace std;
long long ans = 9999999999;
int main(void) {
  string str;
  long long n, x, k;
  cin >> n;
  k = n;
  while (k != 0) {
    str += (k % 10) + '0';
    k /= 10;
  }
  x = k = 1;
  long long str_size = str.size();
  while (n >= x) {
    string s;
    long long j = 0;
    while (x != 0) {
      s += (x % 10) + '0';
      x /= 10;
    }
    long long s_size = s.size();
    for (long long i = 0; i < str_size; i++) {
      if (str[i] == s[j]) j++;
      if (s_size == j) break;
    }
    if (s_size == j) ans = min(ans, str_size - s_size);
    k++;
    x = k * k;
  }
  if (ans == 9999999999)
    cout << "-1";
  else
    cout << ans;
}
