#include <bits/stdc++.h>
using namespace std;
string intos(long long n) {
  string s;
  while (n > 0) {
    char ch = '0' + n % 10;
    s += ch;
    n /= 10;
  }
  reverse((s).begin(), (s).end());
  return s;
}
long long f(string ssq, string sn) {
  long long i, j = 0;
  for (i = 0; i < (long long int)sn.size() && j < (long long int)ssq.size();
       i++)
    if (sn[i] == ssq[j]) j++;
  if (j == (long long int)ssq.size())
    return ((long long int)sn.size() - (long long int)ssq.size());
  else
    return -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, i, j, k, num = 2e9, ans, fans = -1;
    vector<string> v;
    cin >> n;
    for (i = 1; i * i <= 2 * n; i++) v.push_back(intos(i * i));
    long long fl = 0, mn = 1000000007;
    string sn = intos(n);
    for (i = 0; i < (long long int)v.size(); i++) {
      ans = f(v[i], sn);
      if (fl == 0) {
        if (ans != -1) fans = ans, fl = 1;
      } else {
        if (ans != -1) fans = min(fans, ans);
      }
    }
    cout << fans;
  }
  return 0;
}
