n = int(eval(input()))

mn = float("inf")

for i in range(1,n):

  count = 0

  for s in str(i):

    count += int(s)

  for p in str(n-i):

    count += int(p)

  if count < mn:

    mn = count

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

mn = float("inf")

for i in range(1,n):

  if sum(map(int,str(i))) + sum(map(int,str(n-i))) < mn:

    mn = sum(map(int,str(i))) + sum(map(int,str(n-i)))

print(mn)
n = int(eval(input()))
mn = float("inf")
for i in range(1, n):
    count = 0
    for s in str(i):
        count += int(s)
    for p in str(n - i):
        count += int(p)
    if count < mn:
        mn = count
print(mn)

n = int(eval(input()))
mn = float("inf")
for i in range(1, n):
    if sum(map(int, str(i))) + sum(map(int, str(n - i))) < mn:
        mn = sum(map(int, str(i))) + sum(map(int, str(n - i)))
print(mn)

-    count = 0 -    for s in str(i): -        count += int(s) -    for p in str(n - i): -        count += int(p) -    if count < mn: -        mn = count +    if sum(map(int, str(i))) + sum(map(int, str(n - i))) < mn: +        mn = sum(map(int, str(i))) + sum(map(int, str(n - i)))