import java.math.BigDecimal
import java.util.*

fun toSumOfNumbers(n: BigDecimal): BigDecimal {

    tailrec fun toSumOfNumbers(acc: BigDecimal, n: BigDecimal): BigDecimal {
        return if (n == BigDecimal.ZERO) acc
        else toSumOfNumbers(acc + n % BigDecimal.TEN, n.divideToIntegralValue(BigDecimal.TEN))
    }

    return toSumOfNumbers(BigDecimal.ZERO, n)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val list = mutableListOf<BigDecimal>()
    while (true) {
        val x = scanner.nextBigDecimal()
        if (x == BigDecimal.ZERO) {
            break
        }
        list.add(x)
    }
    list.forEach {
        println(toSumOfNumbers(it))
    }
}

