import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto k = readln.chomp.to!long;

  auto ans = int.max;
  foreach (i; 1..10_000_000)
    ans = min(ans, s(i*k));
  writeln(ans);
}

auto s(long n)
{
  auto r = 0;
  while (n > 0) {
    r += n % 10;
    n /= 10;
  }
  return r;
}
