#include <bits/stdc++.h>
using namespace std;
int main() {
  char s1[50];
  int n = sqrt(2 * 1000000000);
  while (~scanf("%s", s1)) {
    int len1 = strlen(s1);
    char s2[50];
    int minn = 0x3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      int temp = i * i;
      int len2 = 1;
      while (temp / 10) {
        s2[len2++] = temp % 10 + '0';
        temp = temp / 10;
      }
      s2[len2] = temp + '0';
      if (len2 > len1) break;
      int node = len2;
      for (int j = 0; j < len1; j++) {
        if (s1[j] == s2[node]) node--;
        if (node == 0) break;
      }
      int ans;
      if (node == 0) {
        ans = len1 - len2;
        minn = min(minn, ans);
      }
    }
    if (minn == 0x3f3f3f3f)
      printf("-1\n");
    else
      printf("%d\n", minn);
  }
  return 0;
}
