#include <bits/stdc++.h>
using namespace std;
int res = INT_MAX;
bool check(double x) {
  if (x == 0) return false;
  int a = x;
  return x == (double)a;
}
int getLen(int n) {
  int x = 0;
  for (; n; n /= 10, x++)
    ;
  return x;
}
int getNum(int n, int len, int ind) {
  long long Mod = 1;
  for (int i = 0; i < ind; i++) {
    Mod *= 10;
  }
  int left = n % Mod;
  n /= 10;
  int subleft = n % Mod;
  n -= subleft;
  n += left;
  return n;
}
void bfs(int n) {
  bool p = true;
  int temp = n, len, cur;
  queue<int> q;
  q.push(n);
  while (q.size()) {
    temp = q.front();
    q.pop();
    if (check(sqrt(temp))) {
      res = min(res, getLen(n) - getLen(temp));
      p = false;
    }
    len = getLen(temp);
    for (int i = 0; i < len; i++) {
      cur = getNum(temp, len, i);
      q.push(cur);
    }
  }
  if (p) res = -1;
}
int main() {
  int n, x;
  cin >> n;
  bfs(n);
  cout << res << endl;
  return 0;
}
