#include <bits/stdc++.h>
using namespace std;
long long N, a[19];
map<long long, int> m;
struct Node {
  long long x;
  int num;
};
int bfs() {
  int ans = 999999999;
  Node s;
  s.num = 0;
  s.x = N;
  queue<Node> q;
  q.push(s);
  while (!q.empty()) {
    Node u = q.front();
    q.pop();
    if (u.num >= ans) continue;
    long long n = u.x;
    long long temp = (long long)sqrt(n);
    if (temp * temp == n) {
      ans = min(ans, u.num);
      continue;
    }
    if (m[n] == 1) continue;
    m[n] = 1;
    int i;
    for (i = 1; i <= 12; i++) {
      if (n < a[i])
        break;
      else {
        long long temp = (n / a[i]) * a[i - 1] + n % a[i - 1];
        if (temp > 0) {
          Node p;
          p.num = u.num + 1;
          p.x = temp;
          q.push(p);
        }
      }
    }
    if (i >= 2 && (n / a[i - 2]) % 10 == 0) continue;
    temp = n % a[i - 1];
    if (temp > 0) {
      Node p;
      p.num = u.num + 1;
      p.x = temp;
      q.push(p);
    }
  }
  if (ans != 999999999) return ans;
  return -1;
}
int main() {
  a[0] = 1;
  for (int i = 1; i <= 11; i++) a[i] = a[i - 1] * 10;
  cin >> N;
  int ans;
  ans = bfs();
  cout << ans << endl;
  return 0;
}
