#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000001;
struct num {
  string str;
  int ans;
};
long long inum[1500];
int main() {
  string strfirst;
  while (cin >> strfirst) {
    num first, temp;
    memset(inum, 0, sizeof(inum));
    first.str = strfirst;
    first.ans = 0;
    queue<num> q;
    q.push(first);
    int k = 0;
    bool flag = true;
    while (!q.empty()) {
      temp = q.front();
      q.pop();
      long long number = 0;
      for (int i = 0; i < (int)temp.str.length(); i++) {
        number = number * 10 + temp.str[i] - ('0' - 0);
      }
      if (fabs((int)sqrt(number) - sqrt(number)) <= EPS && number &&
          temp.str[0] != '0') {
        flag = false;
        break;
      }
      for (int i = 0; i < (int)temp.str.length(); i++) {
        num temp2;
        number = 0;
        bool usedflag = true;
        temp2.str = temp.str;
        temp2.ans = temp.ans + 1;
        temp2.str.erase(temp2.str.begin() + i);
        if (temp2.str[0] == '0') {
          q.push(temp2);
          continue;
        }
        for (int i = 0; i < (int)temp2.str.length(); i++) {
          number = number * 10 + temp2.str[i] - ('0' - 0);
        }
        for (int i = 0; i < k; i++) {
          if (inum[i] == number) {
            usedflag = false;
          }
        }
        if (usedflag) {
          inum[k] = number;
          k++;
          q.push(temp2);
        }
      }
    }
    if (flag)
      cout << -1 << endl;
    else
      cout << temp.ans << endl;
  }
  return 0;
}
