#include <iostream>
using namespace std;
int main() {
unsigned long long int k = 0;
while (cin >> k) {
unsigned int result = 0;
if (k == 0) {
break;
}
while (true) {
if (result < 10 && k == 0) {
break;
}
else if (result > 9 && k == 0) {
k = result;
result = 0;
}
result += k % 10;
k /= 10;
}
cout << result << endl;
}
return 0;
}