#include<stdio.h>
#include<string.h>
int main() {
    int n = 0;
    scanf("%d", &n);
    int i = n;
    int sum = 0;
    while (n > 10) {
        sum = 0;
        while (i) {
            sum += i % 10;
            i /= 10;
        }
        n = sum;
        i = n;
    }
    printf("%d", n);
    return 0;
}