#include <stdio.h>

int main() 
{
    int n = 0;
    while (~scanf("%d", &n))
    {
        again:
        ;
        int sum = 0;
        int cnt = 0;//计数器
        while (n != 0)
        {
            sum += n % 10;
            cnt++;
            n /= 10;
        }
        n = sum;
        if (cnt != 1)
        {
            goto again;
        }
        printf("%d\n", sum);
    }
    return 0;
}