#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[20];
const ll INF=1e18;
ll compute(ll num)
{
    ll ans=0;
    while(num)
    {
        ans+=(num%10);
        num/=10;
    }
    return ans;
}
int main()
{
    ll n;
    //cout<<compute(12)<<endl;
    scanf("%lld",&n);

    for(ll i=0;i<9;i++)
    {
        arr[i]=n*(i+1);
    }
    sort(arr,arr+9);
    ll minn=INF;
    ll num=0;
    do
    {
        num=0;
        for(ll i=0;i<9;i++)
        {
            num=num*10+arr[i];
            minn=min(minn,compute(num));
        }
    }while(next_permutation(arr,arr+9));
    printf("%lld\n",minn);
    return 0;
}
