n=int(eval(input()))

ans=10**6

for i in range(1,n):

    a=list(map(int,list(str(i))))

    b=list(map(int,list(str(n-i))))

    c=sum(a)+sum(b)

    ans=min(ans,c)

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

ans=10**6

for i in range(1,n+1):

    a=i

    b=n-i

    if a<=b:

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

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

        if ans>(asum+bsum):

            ans=asum+bsum

print(ans)
n = int(eval(input()))
ans = 10**6
for i in range(1, n):
    a = list(map(int, list(str(i))))
    b = list(map(int, list(str(n - i))))
    c = sum(a) + sum(b)
    ans = min(ans, c)
print(ans)

n = int(eval(input()))
ans = 10**6
for i in range(1, n + 1):
    a = i
    b = n - i
    if a <= b:
        asum = sum(map(int, str(a)))
        bsum = sum(map(int, str(b)))
        if ans > (asum + bsum):
            ans = asum + bsum
print(ans)

-for i in range(1, n): -    a = list(map(int, list(str(i)))) -    b = list(map(int, list(str(n - i)))) -    c = sum(a) + sum(b) -    ans = min(ans, c) +for i in range(1, n + 1): +    a = i +    b = n - i +    if a <= b: +        asum = sum(map(int, str(a))) +        bsum = sum(map(int, str(b))) +        if ans > (asum + bsum): +            ans = asum + bsum