#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<long long> E;
int a[20], b[20];
void Getnum(long long n, int *a) {
  int &k = a[0];
  k = 0;
  while (n) {
    a[++k] = n % 10;
    n /= 10;
  }
  for (int i = 1; i <= k / 2; i++) swap(a[i], a[k + 1 - i]);
}
bool cmp() {
  int p = 1;
  for (int i = 1; i <= b[0]; i++) {
    while (p <= a[0] && a[p] != b[i]) p++;
    if (p > a[0]) return false;
    p++;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  Getnum(n, a);
  for (long long i = 1; i * i <= n; i++) E.push_back(i * i);
  for (int i = E.size() - 1; i >= 0; i--) {
    Getnum(E[i], b);
    if (cmp()) {
      cout << a[0] - b[0] << '\n';
      return 0;
    }
  }
  cout << "-1\n";
}
