#include<cstdio>
#include<cmath>
typedef __int64 LL;
bool Judge(LL x,LL s) {
LL sum=0;
while(x) {
sum=sum+x%10; x/=10;
}
return sum==s;
}
int main()
{
LL N;
while(~scanf("%I64d",&N)) {
LL n=17*9,ans=-1;
for(int i=1;i<=n;++i) {
LL t=i*i+4*N;
LL tem=sqrt(t);
if(tem*tem==t) if( (tem-i)%2==0) {
LL x=(tem-i)>>1;
if(Judge(x,i)) {
ans=x; break;
}
}
}
printf("%I64d\n",ans);
}
return 0;
}