n = int(eval(input()))

N = n//2

ans = float("INF")

for i in range(1,N+1):

  a,b = list(str(i)), list(str(n-i))

  A,B = sum(list(map(int, a))), sum(list(map(int, b)))

  if ans > A+B: ans = A+B

print(ans)
n = int(eval(input()))

ans = 10**5+1

for a in range(1, n//2+1):

    a,b = list(str(a)), list(str(n-a))

    ans = min(ans, sum(list(map(int, a)))+sum(list(map(int, b))))

print(ans)
n = int(eval(input()))
N = n // 2
ans = float("INF")
for i in range(1, N + 1):
    a, b = list(str(i)), list(str(n - i))
    A, B = sum(list(map(int, a))), sum(list(map(int, b)))
    if ans > A + B:
        ans = A + B
print(ans)

n = int(eval(input()))
ans = 10**5 + 1
for a in range(1, n // 2 + 1):
    a, b = list(str(a)), list(str(n - a))
    ans = min(ans, sum(list(map(int, a))) + sum(list(map(int, b))))
print(ans)

-N = n // 2 -ans = float("INF") -for i in range(1, N + 1): -    a, b = list(str(i)), list(str(n - i)) -    A, B = sum(list(map(int, a))), sum(list(map(int, b))) -    if ans > A + B: -        ans = A + B +ans = 10**5 + 1 +for a in range(1, n // 2 + 1): +    a, b = list(str(a)), list(str(n - a)) +    ans = min(ans, sum(list(map(int, a))) + sum(list(map(int, b))))