#include <bits/stdc++.h>
using namespace std;
bool match(string s, string t) {
  int pos = 0;
  for (char digit : t) {
    while (pos < s.size() && s[pos] != digit) {
      ++pos;
    }
    if (pos >= s.size()) {
      return false;
    }
    ++pos;
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  int ans = s.size();
  for (int i = 1; i * i <= n; ++i) {
    string t = to_string(i * i);
    if (match(s, t)) {
      ans = min(ans, (int)(s.size() - t.size()));
    }
  }
  if (ans == s.size()) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
