#include <bits/stdc++.h>
using namespace std;
struct point {
  point *next[10];
  int cnt;
  bool flag, chk;
};
int n, i, ans = 0, cnt = 0;
point *p0;
void initP(point *p) {
  for (int i = 0; i < 10; i++) p->next[i] = NULL;
  p->flag = false;
  p->chk = false;
  p->cnt = 0;
}
void insertP(int x) {
  int i, y;
  stack<int> s;
  point *p = p0;
  while (x > 0) {
    s.push(x % 10);
    x /= 10;
  }
  while (!s.empty()) {
    y = s.top();
    s.pop();
    if (p->next[y] != NULL)
      p = p->next[y];
    else {
      point *pt;
      pt = new point;
      initP(pt);
      pt->cnt = p->cnt + 1;
      p->next[y] = pt;
      p = pt;
    }
  }
  p->flag = true;
}
int main() {
  p0 = new point;
  initP(p0);
  cin >> n;
  for (i = 1; i * i <= n; i++) insertP(i * i);
  stack<int> s;
  vector<point *> v;
  v.push_back(p0);
  p0->chk = true;
  while (n > 0) {
    s.push(n % 10);
    n /= 10;
    cnt++;
  }
  while (!s.empty()) {
    int x = s.top();
    s.pop();
    for (i = v.size() - 1; i >= 0; i--)
      if (v[i]->next[x] != NULL && !v[i]->next[x]->chk) {
        v[i]->next[x]->chk = true;
        v.push_back(v[i]->next[x]);
        if (v[i]->next[x]->flag) ans = max(ans, v[i]->next[x]->cnt);
      }
  }
  if (ans == 0)
    cout << -1 << endl;
  else
    cout << cnt - ans << endl;
  return 0;
}
