N=int(eval(input()))

ans=100000000000

for A in range(1,N):

    B=N-A

    sa=0

    sb=0

    for i in range(len(str(A))):

        sa+=A%10

        A=(A-A%10)//10

    for j in range(len(str(B))):

        sb+=B%10

        B=(B-B%10)//10

    if sa+sb<ans:

        ans=sa+sb



print(ans)

N=int(eval(input()))

ans=100000000000

for a in range(1,N):

    b=N-a

    tempa=0

    tempb=0

    for i in range(len(str(a))):

        tempa+=a%10

        a=a//10

    for j in range(len(str(b))):

        tempb+=b%10

        b=b//10

    if tempa+tempb<ans:

        ans=tempa+tempb



print(ans)

N = int(eval(input()))
ans = 100000000000
for A in range(1, N):
    B = N - A
    sa = 0
    sb = 0
    for i in range(len(str(A))):
        sa += A % 10
        A = (A - A % 10) // 10
    for j in range(len(str(B))):
        sb += B % 10
        B = (B - B % 10) // 10
    if sa + sb < ans:
        ans = sa + sb
print(ans)

N = int(eval(input()))
ans = 100000000000
for a in range(1, N):
    b = N - a
    tempa = 0
    tempb = 0
    for i in range(len(str(a))):
        tempa += a % 10
        a = a // 10
    for j in range(len(str(b))):
        tempb += b % 10
        b = b // 10
    if tempa + tempb < ans:
        ans = tempa + tempb
print(ans)

-for A in range(1, N): -    B = N - A -    sa = 0 -    sb = 0 -    for i in range(len(str(A))): -        sa += A % 10 -        A = (A - A % 10) // 10 -    for j in range(len(str(B))): -        sb += B % 10 -        B = (B - B % 10) // 10 -    if sa + sb < ans: -        ans = sa + sb +for a in range(1, N): +    b = N - a +    tempa = 0 +    tempb = 0 +    for i in range(len(str(a))): +        tempa += a % 10 +        a = a // 10 +    for j in range(len(str(b))): +        tempb += b % 10 +        b = b // 10 +    if tempa + tempb < ans: +        ans = tempa + tempb