#include <bits/stdc++.h>
using namespace std;
int lcs(string X, string Y) {
  int i, j, m = X.length(), n = Y.length();
  int L[m + 1][n + 1];
  for (i = 0; i <= m; i++) {
    for (j = 0; j <= n; j++) {
      if (i == 0 || j == 0)
        L[i][j] = 0;
      else if (X[i - 1] == Y[j - 1])
        L[i][j] = L[i - 1][j - 1] + 1;
      else
        L[i][j] = max(L[i - 1][j], L[i][j - 1]);
    }
  }
  return L[m][n];
}
int main() {
  long long n;
  cin >> n;
  vector<long long> v;
  string x, y;
  x = to_string(n);
  int max = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    v.push_back(i * i);
    y = to_string(i * i);
    if (max < lcs(x, y) && (lcs(x, y) == y.length())) {
      max = lcs(x, y);
    }
  }
  if (max != 0) {
    cout << x.length() - max;
  } else {
    cout << "-1";
  }
  return 0;
}
