#include <bits/stdc++.h>
using namespace std;
int ar[50000];
int vis[20];
int gl(int a, int b) {
  return (int)(to_string(a).length() - to_string(b).length());
}
bool fi(string s, int a) {
  string str = to_string(a);
  int i = 0, j = 0;
  while (i < s.length() && j < str.length()) {
    if (s[i] == str[j]) {
      i++;
      j++;
    } else {
      i++;
    }
  }
  if (j == str.length()) return true;
  return false;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < 50000; i++) {
    ar[i] = i * i;
  }
  string m = to_string(n);
  int ans = -1;
  for (int i = 1; i < 50000; i++) {
    if (ar[i] > n) break;
    if (fi(m, ar[i])) {
      int diff = gl(n, ar[i]);
      ans = max(ans, ar[i]);
    }
  }
  if (ans != -1)
    cout << gl(n, ans) << endl;
  else
    cout << -1 << endl;
  return 0;
}
