#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int vis[100];
int vv[100];
vector<long long> vecorg;
int main() {
  long long n;
  cin >> n;
  long long temp = n;
  int corg = 0;
  while (temp != 0) {
    int uu = temp % 10;
    vecorg.push_back(uu);
    vv[uu]++;
    temp /= 10;
    corg++;
  }
  for (int i = 1; i <= 200000; i++) {
    long long pp = 1LL * i * i;
    if (pp <= n)
      v.push_back(pp);
    else
      break;
  }
  long long min = 2000000001;
  int cnt = 0;
  vector<long long> vec;
  for (int i = 0; i < v.size(); i++) {
    long long tt = v[i];
    vec.clear();
    while (tt != 0) {
      vec.push_back(tt % 10);
      tt /= 10;
    }
    int c = 0, j = 0;
    for (int i = 0; i < vecorg.size(); i++) {
      if (vec[j] == vecorg[i]) {
        c++;
        j++;
      }
    }
    if (j == vec.size()) {
      if (min > corg - c) {
        min = corg - c;
      }
    }
  }
  if (min == 2000000001)
    cout << -1 << endl;
  else
    cout << min << endl;
}
