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;

enum N = 100_000;
ulong[N] memo = ulong.max;
ulong[N] uuee = ulong.max;
ulong[N] sika = ulong.max;

void main()
{
  ulong k = readln.chomp.to!ulong;
  ulong l = k;
  for (int i = 0; i < N; ++i) {
    ulong ue = l / N;
    long sum = 0;
    while (ue) {
      sum += ue % 10;
      ue /= 10;
    }
    ulong sita = l % N;
    ulong m = sita;
    long sum2 = 0;
    while (m) {
      sum2 += m % 10;
      m /= 10;
    }
    if (sum < memo[sita]) {
      memo[sita] = sum;
      uuee[sita] = ue;
    }
    sika[sita] = sum2;
    l += k;
  }
  ulong ans = ulong.max;
  foreach (i, v; sika) {
    if (v == ulong.max) {
      continue;
    }
    ulong sub = memo[uuee[i]] + v;
    ans = min(ans, sub);
  }
  ans.writeln;
}
