N = int(eval(input()))

cmin = 10**5

for x in range(1,N):

    y = str(N-x)

    x = str(x)

    cnt = 0

    for i in range(len(x)):

        cnt += int(x[i])

    for j in range(len(y)):

        cnt += int(y[j])

    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 = 10**5
for x in range(1, N):
    y = str(N - x)
    x = str(x)
    cnt = 0
    for i in range(len(x)):
        cnt += int(x[i])
    for j in range(len(y)):
        cnt += int(y[j])
    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)

-cmin = 10**5 -for x in range(1, N): -    y = str(N - x) -    x = str(x) +cmin = 1000 +for i in range(1, N): +    a = str(i) -    for i in range(len(x)): -        cnt += int(x[i]) -    for j in range(len(y)): -        cnt += int(y[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])