#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 998244353;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string a = to_string(n);
  int mn = 1e9;
  for (int i = 1;; i++) {
    if (i * i > n) break;
    int c = 0;
    string cur = to_string(i * i);
    int ind = 0;
    for (int j = 0; j < ((int)(a).size()); j++) {
      if (ind < ((int)(cur).size()) && a[j] == cur[ind])
        ind++;
      else
        c++;
    }
    if (ind == ((int)(cur).size())) mn = min(mn, c);
  }
  if (mn == 1e9) mn = -1;
  cout << mn;
  return 0;
}
