#include <iostream>
#include <string>
using namespace std;
int solve(int x){
if(x < 10){
return x;
}
int sum = 0;
while(x > 0){
sum += x % 10;
x /= 10;
}
return solve(sum);
}
int main(){
int x;
while(cin >> x){
if(x == 0)
break;
cout << solve(x) << endl;
}
return 0;
}