#include <iostream>

using namespace std;

int x = 0;
int checkSum (int n){
    int sum = 0;
    while (n != 0){
        sum += n % 10;
        n /= 10;
    }
    x = sum;
    if (x >= 10){
        checkSum(x);
    }
    return x;
}
int main() {
    int n;
    while(scanf ("%d", &n) != EOF){
         cout <<  checkSum(n) << endl;
    }
}

初出茅庐,请多指教