#include <bits/stdc++.h>
using namespace std;
string num;
long long ans;
long long check(long long x) {
  string a = to_string(x);
  long long voy = 0;
  for (long long i = 0; i < num.size(); i++) {
    if (voy == a.size()) continue;
    if (a[voy] == num[i]) voy++;
  }
  if (voy != a.size()) return -1;
  return num.size() - a.size();
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> num;
  ans = 1e9;
  for (long long i = 1; i <= 44721; i++) {
    long long tmp = check(i * i);
    if (tmp != -1) ans = min(ans, tmp);
  }
  if (ans == 1e9)
    cout << "-1\n";
  else
    cout << ans << "\n";
  return 0;
}
