#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int bit(ll x)
{
    int sum=0;
    while(x)
    {
        sum+=x%10;
        x/=10;
    }
    return sum;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
#else

#endif // LOCAL
    ll k;
    scanf("%lld",&k);
    int minn=bit(k);
    for(int i=2;i<=5000000;i++)
    {
        minn=min(bit(k),bit(ll(k*i)));
    }
    printf("%d",minn);
    return 0;
}

