#include<bits/stdc++.h>
using namespace std;
class LastDigit
{
int d = 0;
long long int f(long long int x)
{
long long int sum = 0;
while(x != 0)
{
d++;
sum = sum + x;
//cout << sum << " ";
x =x/10;
}
return sum;
}
public:
long long findX(long long S)
{
//return f(900000000000000000);
long long int i;
f(S);
int dig = d;
int d1 = dig -1;
int ans = -1;
double a1 = (double)(pow(10,d1) -1) / (9*pow(10,d1-1));
d1++;
double a2 = (double)(pow(10,d1) -1) / (9*pow(10,d1-1));
a1 = 1/a1;
a2 = 1/a2;
a1 = S*a1;
a2 = S*a2;
for(i=a1 - 100 ; i <= a1 + 100 ; i++)
if(f(i) - S == (long long )0)
return i;
for(i = a2 - 100 ;i <= a2 + 100 ; i++)
if(f(i) - S == (long long )0)
return i;
return ans;
}
};
int main()
{
class LastDigit ld;
cout << ld.findX(837592744927492746);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY2xhc3MgTGFzdERpZ2l0CiAgICB7CiAgICAJaW50IGQgPSAwOwogICAgCWxvbmcgbG9uZyBpbnQgZihsb25nIGxvbmcgaW50IHgpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgCQogICAgICAgICAgICAJbG9uZyBsb25nIGludCBzdW0gPSAwOwogICAgICAgICAgICAJd2hpbGUoeCAhPSAwKQogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAJZCsrOwogICAgICAgICAgICAgICAgICAgIAlzdW0gPSBzdW0gKyB4OwogICAgICAgICAgICAgICAgICAgIAkvL2NvdXQgPDwgc3VtIDw8ICIgIjsKICAgICAgICAgICAgICAgICAgICAJeCA9eC8xMDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIAlyZXR1cm4gc3VtOwogICAgICAgICAgICB9CiAgICAJcHVibGljOgogICAgCWxvbmcgbG9uZyBmaW5kWChsb25nIGxvbmcgUykKICAgICAgICAgICAgewogICAgICAgICAgICAJLy9yZXR1cm4gZig5MDAwMDAwMDAwMDAwMDAwMDApOwogICAgICAgICAgICAJbG9uZyBsb25nIGludCBpOwogICAgICAgICAgICAJZihTKTsKICAgICAgICAgICAgCWludCBkaWcgPSBkOwogICAgICAgICAgICAJaW50IGQxID0gZGlnIC0xOwogICAgICAgICAgICAJaW50IGFucyA9IC0xOwogICAgICAgICAgICAJZG91YmxlIGExID0gKGRvdWJsZSkocG93KDEwLGQxKSAtMSkgLyAoOSpwb3coMTAsZDEtMSkpOwogICAgICAgICAgICAJZDErKzsKICAgICAgICAgICAgCWRvdWJsZSBhMiA9IChkb3VibGUpKHBvdygxMCxkMSkgLTEpIC8gKDkqcG93KDEwLGQxLTEpKTsKICAgICAgICAgICAgCWExID0gMS9hMTsKICAgICAgICAgICAgCWEyID0gMS9hMjsKICAgICAgICAgICAgCWExID0gUyphMTsKICAgICAgICAgICAgCWEyID0gUyphMjsKICAgICAgICAgICAgCWZvcihpPWExIC0gMTAwIDsgaSA8PSBhMSArIDEwMCA7IGkrKykKICAgICAgICAgICAgICAgICAgICBpZihmKGkpIC0gUyA9PSAobG9uZyBsb25nICkwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgICAgICAgZm9yKGkgPSBhMiAtIDEwMCA7aSA8PSBhMiArIDEwMCA7IGkrKykKICAgICAgICAgICAgICAgICAgICBpZihmKGkpIC0gUyA9PSAobG9uZyBsb25nICkwKQogICAgICAgICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgICAgICAgcmV0dXJuIGFuczsKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgfQogICAgfTsKICAgIGludCBtYWluKCkKICAgIHsKICAgIAljbGFzcyBMYXN0RGlnaXQgbGQ7CiAgICAJY291dCA8PCBsZC5maW5kWCg4Mzc1OTI3NDQ5Mjc0OTI3NDYpOwogICAgCXJldHVybiAwOwogICAgfQ==