#include <bits/stdc++.h>
using namespace std;
unordered_map<string, bool> mp;
string s;
int len;
map<string, int> dp[15];
int solve(int ind = 0, int flg = 0, string str = "", int sum = 0) {
  if (ind == len) {
    if (mp.find(str) != mp.end()) {
      return 0;
    }
    return 99999;
  }
  if (dp[ind].find(str) != dp[ind].end()) return dp[ind][str];
  int ret;
  ret = min(solve(ind + 1, 1, str + s[ind], sum + (s[ind] - '0')),
            solve(ind + 1, 0, str, sum) + 1);
  return dp[ind][str] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  for (long long i = 1;; i++) {
    long long val = i * i;
    if (val > 2000000000) break;
    mp[to_string(val)] = 1;
    if (i == 1) continue;
    while (1) {
      val *= val;
      if (val > 2000000000) break;
      mp[to_string(val)] = 1;
    }
  }
  cin >> s;
  len = s.size();
  int ans = solve();
  if (ans > 9)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
