#include <stdio.h>
#include <string.h>

int root(int number) {
    int cnt = 0;
    while (number != 0) {
	  //获取各个位的数值
        cnt += (number % 10);
        number /= 10;
    }
    if (cnt < 10) {
        return cnt;
    } else {
        return root(cnt);
    }
}
int main() {
    int number;
    while (scanf("%d", &number) != EOF) {
        printf("%d\n", root(number));
    }
    return 0;
}