#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
long long arr[N];
vector<int> G;
struct node {
  string x;
  int d;
};
int main() {
  string str;
  cin >> str;
  node t = {str, 0};
  map<long long, int> mp;
  map<string, int> mp1;
  for (long long i = 1; i < 1e5; i++) {
    mp[i * i] = 1;
  }
  queue<node> q;
  q.push(t);
  mp1[str] = 1;
  while (!q.empty()) {
    t = q.front();
    q.pop();
    string s = t.x;
    int sum = (int)s[0] - '0';
    for (int i = 1; i < s.size(); i++) {
      sum = sum * 10 + int(s[i] - '0');
    }
    if (s[0] != '0' && mp.count(sum)) {
      cout << t.d << endl;
      return 0;
    }
    for (int i = 0; i < s.size(); i++) {
      string s1 = s.substr(0, i) + s.substr(i + 1, s.size() - 1 - i);
      if (!mp1.count(s1)) {
        mp1[s1] = 1;
        node tt = {s1, t.d + 1};
        q.push(tt);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
