//* Problem  : 1551 - Digital Roots
//* Contest  : acm.tju.edu.cn
//* Type     : Solution
//* Date     : 2007.07.24
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 6.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

//#define ONLINE_JUDGE
char s[100000];

int main()
{
	int n, t, i;
	while (scanf("%s", s) == 1 && s[0] != '0')
	{
		n = 0; i = 0;
		while (s[i]) n += s[i++]-'0';
		while (n > 9)
		{
			t = 0;
			while (n)
			{
				t += n%10;
				n /= 10;
			}
			n = t;		
		}
		printf("%d\n", n);
	}
}
