#include <cstdlib> #include <iostream> #include <map> #include <sstream> using namespace std; char ch[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; int main(int argc, char *argv[]) { //freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); map<char, int> refTable; for(int i=0; i<10; i++) refTable.insert(make_pair(ch[i], i)); string value; while(cin >> value && value != "0") { while(value.size() > 1) { int sum = 0; int size = value.size(); for(int i=0; i<size; i++) sum += refTable[value[i]]; stringstream ss; ss << sum; ss >> value; } cout << value << endl; } return EXIT_SUCCESS; }