#include <stdio.h>

int main() {
    int num,sum;
    while(scanf("%d",&num)!=EOF){
        if(num<10)
            printf("%d\n",num);
        else{
            
           do{
            sum=0; 
            while(num>0){
                sum=sum+num%10;
                num=num/10;
            }
            num=sum;
           }while(sum>=10);
        }
        printf("%d\n",sum);
    }
    return 0;
}