#include <bits/stdc++.h>
using namespace std;
long long n, digit[10003], digit2[10003], idx;
long long check(long long x) {
  x = powl(x, 2);
  int idx2 = 0;
  if (x == 0) digit2[idx2++] = 0;
  while (x != 0) {
    digit2[idx2++] = x % 10;
    x /= 10;
  }
  reverse(digit2, digit2 + idx2);
  long long c = 0;
  for (int i = 0; i < idx; i++) {
    if (c == idx2) break;
    if (digit[i] == digit2[c]) c++;
  }
  return (c == idx2 && c > 0) ? idx - c : -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie();
  cin >> n;
  long long m = n;
  while (n != 0) {
    digit[idx++] = n % 10;
    n /= 10;
  }
  reverse(digit, digit + idx);
  long long res = 1e18;
  for (long long i = 1; i <= 3000000; i++) {
    long long x = check(i);
    if (x != -1) res = min(res, x);
  }
  if (res == 1e18)
    cout << -1;
  else
    cout << res;
  return 0;
}
