N = int(eval(input()))

factor_a = []

factor_b = []

ans = N

for a in range(1, N):

    sum_a = sum([int(i) for i in str(a)])

    sum_b = sum([int(i) for i in str(N-a)])

    if sum_a + sum_b < ans:

        ans = sum_a + sum_b

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

ans = N





def simulate(m):

    for a in range(1, m):

        global ans

        sum_a = sum([int(i) for i in str(a)])

        sum_b = sum([int(i) for i in str(N-a)])

        if sum_a + sum_b < ans:

            ans = sum_a + sum_b





if N % 2 == 0:

    simulate(N//2+1)

else:

    simulate(N//2+2)



print(ans)
N = int(eval(input()))
factor_a = []
factor_b = []
ans = N
for a in range(1, N):
    sum_a = sum([int(i) for i in str(a)])
    sum_b = sum([int(i) for i in str(N - a)])
    if sum_a + sum_b < ans:
        ans = sum_a + sum_b
print(ans)

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


def simulate(m):
    for a in range(1, m):
        global ans
        sum_a = sum([int(i) for i in str(a)])
        sum_b = sum([int(i) for i in str(N - a)])
        if sum_a + sum_b < ans:
            ans = sum_a + sum_b


if N % 2 == 0:
    simulate(N // 2 + 1)
else:
    simulate(N // 2 + 2)
print(ans)

-factor_a = [] -factor_b = [] -for a in range(1, N): -    sum_a = sum([int(i) for i in str(a)]) -    sum_b = sum([int(i) for i in str(N - a)]) -    if sum_a + sum_b < ans: -        ans = sum_a + sum_b + + +def simulate(m): +    for a in range(1, m): +        global ans +        sum_a = sum([int(i) for i in str(a)]) +        sum_b = sum([int(i) for i in str(N - a)]) +        if sum_a + sum_b < ans: +            ans = sum_a + sum_b + + +if N % 2 == 0: +    simulate(N // 2 + 1) +else: +    simulate(N // 2 + 2)