2017.11.24
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
long long num;
long long sum;
int ch;
while(1){
sum = 0;
ch = getchar();
if(ch == '0')
break;
while(ch != '\n'){
sum += ch - 48;
ch = getchar();
}
num = sum;
sum = 0;
if(num < 10)
cout << num << endl;
else{
while(1){
while(num != 0){
sum += num % 10;
num = num /10;
}
if(sum < 10){
cout << sum << endl;
break;
}
num = sum;
sum = 0;
}
}
}
return 0;
}