#include<iostream>

const int MAX_N = 1000;
int N;
std::string dp[MAX_N+10][MAX_N+10];

/*
 * compares two integers represented as strings
 * if what>competitor, 'what' value copies 'competitor' value
 * returns true if value was copied, false otherwise
 */
bool reduce(std::string& what, const std::string& competitor)
{
    int wlen = what.length(), clen = competitor.length();
    if (!wlen)
    {
        what = competitor;
        return true;
    }

    bool competitorIsLesser = false;
    if (wlen != clen)
        competitorIsLesser = wlen>clen;
    else
    {
        for (int i = 0; i < wlen; ++i)
            if (what[i] != competitor[i])
            {
                competitorIsLesser = what[i]>competitor[i];
                break;
            }
    }

    if (competitorIsLesser)
    {
        what = competitor;
        return true;
    }

    return false;
}

/*
 * iterate through all possible last digits and adds them to end
 * tries to improve dp values with obtained integer
 * 
 * tricky case: when adding '0', we can refer to previous dp values
 * in this case, function calls recursively on that previous cell if it was improved
 */
void proceed(int sum, int rem)
{
    for (int lastDigit = 9; lastDigit; --lastDigit)
        reduce(dp[sum+lastDigit][(rem*10+lastDigit)%N], dp[sum][rem]+char('0'+lastDigit));

    if (reduce(dp[sum][rem*10%N], dp[sum][rem]+'0') && rem*10%N<rem)
        proceed(sum, rem*10%N);
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    std::cin>>N;
    
    //starting conditions
    for (int lastDigit = 9; lastDigit >= 0; --lastDigit)
        dp[lastDigit][lastDigit%N] = char('0'+lastDigit);

    //dp itself
    for (int sum = 1; sum <= N; ++sum)
        for (int rem = 0; rem < N; ++rem)
            if (dp[sum][rem].length())
                proceed(sum, rem);

    std::cout<<dp[N][0];
}