N = int(eval(input()))

cmin = 1000

for i in range(1,N):

    a = str(i)

    cnt = 0

    for j in range(len(a)):

        cnt += int(a[j])

    b = str(N-i)

    for j in range(len(b)):

        cnt += int(b[j])

    cmin = min(cmin,cnt)

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

cmin = N

for i in range(1,N//2):

    j = N-i

    a = str(i)

    b = str(j)

    cnt = 0

    for k in range(len(a)):

        cnt += int(a[k])

    for k in range(len(b)):

        cnt += int(b[k])

    cmin = min(cmin,cnt)

print(cmin)
N = int(eval(input()))
cmin = 1000
for i in range(1, N):
    a = str(i)
    cnt = 0
    for j in range(len(a)):
        cnt += int(a[j])
    b = str(N - i)
    for j in range(len(b)):
        cnt += int(b[j])
    cmin = min(cmin, cnt)
print(cmin)

N = int(eval(input()))
cmin = N
for i in range(1, N // 2):
    j = N - i
    a = str(i)
    b = str(j)
    cnt = 0
    for k in range(len(a)):
        cnt += int(a[k])
    for k in range(len(b)):
        cnt += int(b[k])
    cmin = min(cmin, cnt)
print(cmin)

-cmin = 1000 -for i in range(1, N): +cmin = N +for i in range(1, N // 2): +    j = N - i +    b = str(j) -    for j in range(len(a)): -        cnt += int(a[j]) -    b = str(N - i) -    for j in range(len(b)): -        cnt += int(b[j]) +    for k in range(len(a)): +        cnt += int(a[k]) +    for k in range(len(b)): +        cnt += int(b[k])