#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int work(int x) {
  string xs = to_string(x);
  int i = 0, j = 0;
  int t = 0;
  while (i < xs.size()) {
    while (j < s.size() && s[j] != xs[i]) {
      j++;
      t++;
    }
    if (j == s.size()) {
      break;
    }
    i++;
    j++;
  }
  if (i >= xs.size()) {
    return (t + s.size() - j);
  }
  return (-1);
}
int main() {
  int n;
  cin >> n;
  s = to_string(n);
  int ans = -1;
  for (int i = 1; i <= floor(sqrt(n)); i++) {
    int t = work(i * i);
    if (t != -1) {
      if (ans == -1 || ans > t) {
        ans = t;
      }
    }
  }
  cout << ans << endl;
  return (0);
}
