#include <iostream>
using namespace std;
int share(int n, int sum);
int main(void)
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
int sum = i;
sum = share(i, sum);
if (sum == n)
{
cout << i << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
int share(int n, int sum)
{
sum += n % 10;
n /= 10;
if (n > 0)
return share(n, sum);
else
return sum;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBzaGFyZShpbnQgbiwgaW50IHN1bSk7CgppbnQgbWFpbih2b2lkKQp7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspCiAgICB7CiAgICAgICAgaW50IHN1bSA9IGk7CiAgICAgICAgc3VtID0gc2hhcmUoaSwgc3VtKTsKCiAgICAgICAgaWYgKHN1bSA9PSBuKQogICAgICAgIHsKICAgICAgICAgICAgY291dCA8PCBpIDw8IGVuZGw7CiAgICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQgPDwgMCA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0KCmludCBzaGFyZShpbnQgbiwgaW50IHN1bSkKewogICAgc3VtICs9IG4gJSAxMDsKICAgIG4gLz0gMTA7CgogICAgaWYgKG4gPiAwKQogICAgICAgIHJldHVybiBzaGFyZShuLCBzdW0pOwogICAgZWxzZQogICAgICAgIHJldHVybiBzdW07Cn0=