import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  ulong k = readln.chomp.to!ulong;
  ulong l = k;
  ulong ans = ulong.max;
  for (int i = 0; i < 7_000_000; ++i) {
    ulong m = l;
    ulong sum = 0;
    while (m) {
      sum += m % 10;
      m /= 10;
    }
    ans = min(ans, sum);
    l += k;
  }
  ans.writeln;
}
