x=int(eval(input()))

count=100000

suma=0

sumb=0

for a in range(1, x):

    b = x-a

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

    if y<count:

        count=y

print(count)
x=int(eval(input()))

count=10000

for a in range(1, x):

    suma=0

    sumb=0

    b=x-a

    while (a > 0):

        suma += a%10

        a= a//10

    while (b > 0):

        sumb += b%10

        b=b//10

    count = min(count, suma+sumb)

print(count)
x = int(eval(input()))
count = 100000
suma = 0
sumb = 0
for a in range(1, x):
    b = x - a
    y = sum(map(int, str(a))) + sum(map(int, str(b)))
    if y < count:
        count = y
print(count)

x = int(eval(input()))
count = 10000
for a in range(1, x):
    suma = 0
    sumb = 0
    b = x - a
    while a > 0:
        suma += a % 10
        a = a // 10
    while b > 0:
        sumb += b % 10
        b = b // 10
    count = min(count, suma + sumb)
print(count)

-count = 100000 -suma = 0 -sumb = 0 +count = 10000 +    suma = 0 +    sumb = 0 -    y = sum(map(int, str(a))) + sum(map(int, str(b))) -    if y < count: -        count = y +    while a > 0: +        suma += a % 10 +        a = a // 10 +    while b > 0: +        sumb += b % 10 +        b = b // 10 +    count = min(count, suma + sumb)