#include<bits/stdc++.h>
using namespace std;
int aa(int n){
int i=n,j=1,x=0,y=0,z=0;
while(i!=0){
z++;
i/=10;
}
i=1;
while(j<=z/2){
x*=10;
i*=10;
x+=n%10;
n/=10;
j++;
}
j=1;
i=i*i;
while(j<=z/2){
y*=10;
y+=n/i;
i/=10;
j++;
}
if(x==y)
return 1;
else
return 0;
}
int main()
{
int i,n,x=0,j=0;
cin>>n;
for(i=0;aa(n)!=1;i++){
j=n;
while(j!=0){
x*=10;
x=j%10;
j/=10;
}
n=n+x;
}
cout<<i;
return 0;
}
/**************************************************************
Problem: 1083
User: houshanglin
Language: C++
Result: Wrong Answer
****************************************************************/