#include<bits/stdc++.h>
using namespace std;
unsigned long long k,minn=INT_MAX,sum;
int main()
{
	scanf("%d",&k);
	for(long long i=k;i<=10000*k;i+=k)
	{
		int ii=i;
		sum=0;
		while(ii)
		{
			sum+=ii%10;
			ii/=10;
		}
		minn=min(minn,sum);
	}
	printf("%d",minn);
	return 0;
}