N = int(eval(input()))

ans = float('inf')

for i in range(N//2):

  A = i+1

  B = N-A

  ans = min(ans, sum(list(map(int,str(A)))) + sum(list(map(int,str(B))) ))



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

ans = 10**9+7

for i in range(1,N):

  A = i

  B = N-i

  ans = min(ans, sum(list(map(int,str(A))))+sum(list(map(int,str(B)))))

print(ans)
N = int(eval(input()))
ans = float("inf")
for i in range(N // 2):
    A = i + 1
    B = N - A
    ans = min(ans, sum(list(map(int, str(A)))) + sum(list(map(int, str(B)))))
print(ans)

N = int(eval(input()))
ans = 10**9 + 7
for i in range(1, N):
    A = i
    B = N - i
    ans = min(ans, sum(list(map(int, str(A)))) + sum(list(map(int, str(B)))))
print(ans)

-ans = float("inf") -for i in range(N // 2): -    A = i + 1 -    B = N - A +ans = 10**9 + 7 +for i in range(1, N): +    A = i +    B = N - i