#include <stdio.h> int main() { int a; while (scanf("%d", &a) != EOF) { int sum=0; while (1) { sum=0; while (a) { sum+=a%10; a/=10; } if (sum<10){ break; }else { a=sum; } } printf("%d\n", sum); } return 0; }