#include <bits/stdc++.h>
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int exp(long long int x, long long int y) {
  long long int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, i, x, a, b, ans;
  cin >> n;
  vector<long long int> v;
  for (i = 1; i * i <= n; i++) v.push_back(i * i);
  for (i = v.size() - 1; i >= 0; i--) {
    ans = 0;
    x = n;
    while (x != 0 && v[i] != 0) {
      a = v[i] % 10;
      while (x != 0) {
        b = x % 10;
        if (a == b)
          break;
        else {
          ans++;
          x = x / 10;
        }
      }
      if (a == b) {
        v[i] = v[i] / 10;
        x = x / 10;
      }
    }
    if (v[i] == 0 && x == 0)
      break;
    else if (v[i] == 0 && x != 0) {
      while (x != 0) {
        ans++;
        x = x / 10;
      }
      break;
    }
  }
  if (v[i] == 0)
    cout << ans;
  else
    cout << -1;
  return 0;
}
