N = int(eval(input()))

ans = 9999999

for a in range(1,N):

    b = N-a

    tmp = 0

    for ac in str(a):

        tmp += int(ac)

    for bc in str(b):

        tmp += int(bc)

    ans = min(ans, tmp)

print(ans)

N = int(eval(input()))



ans = 9999

for a in range(1,N):

    b = N-a

    x = sum(map(int,str(a)))

    y = sum(map(int,str(b)))

    ans = min(ans, x+y)

print(ans)
N = int(eval(input()))
ans = 9999999
for a in range(1, N):
    b = N - a
    tmp = 0
    for ac in str(a):
        tmp += int(ac)
    for bc in str(b):
        tmp += int(bc)
    ans = min(ans, tmp)
print(ans)

N = int(eval(input()))
ans = 9999
for a in range(1, N):
    b = N - a
    x = sum(map(int, str(a)))
    y = sum(map(int, str(b)))
    ans = min(ans, x + y)
print(ans)

-ans = 9999999 +ans = 9999 -    tmp = 0 -    for ac in str(a): -        tmp += int(ac) -    for bc in str(b): -        tmp += int(bc) -    ans = min(ans, tmp) +    x = sum(map(int, str(a))) +    y = sum(map(int, str(b))) +    ans = min(ans, x + y)