#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, l1, mini, l, j1, x1, x, c1, c, n1;
  char n[20], b[20];
  vector<long long int> v[20];
  cin >> n1;
  long long int n11 = n1;
  c = 0;
  while (n11) {
    n11 /= 10;
    c++;
  }
  l1 = c;
  for (i = c - 1; i >= 0; i--) {
    n[i] = (char)((n1 % 10) + 48);
    n1 /= 10;
  }
  for (i = 1; i <= 100000; i++) {
    x = i * i;
    x1 = x;
    c = 0;
    while (x1) {
      x1 /= 10;
      c++;
    }
    l = x / pow(10, c - 1);
    v[l].push_back(x);
  }
  mini = INT_MAX;
  for (i = 0; i < l1; i++) {
    vector<long long int>::iterator it;
    for (it = v[(int)n[i] - 48].begin(); it != v[(int)n[i] - 48].end(); it++) {
      x = *it;
      c = 0;
      while (x != 0) {
        x = x / 10;
        c++;
      }
      if (c > l1)
        break;
      else {
        x = *it;
        for (j = c - 1; j >= 0; j--) {
          b[j] = (char)(x % 10 + 48);
          x = x / 10;
        }
        j1 = i;
        c1 = i;
        for (j = 0; j < c; j++) {
          while (b[j] != n[j1] && j1 < l1) {
            j1++;
            c1++;
          }
          if (j1 == l1) break;
          j1++;
        }
        c1 = c1 + l1 - j1;
        if (j == c) mini = min(mini, c1);
      }
    }
  }
  if (mini == l1 || mini == INT_MAX)
    cout << -1 << "\n";
  else
    cout << mini << "\n";
}
