#include <stdio.h>
int resolve(int A)
{
int result,i;
int a[10]={0};
int mid_result=0;
for(i=0;i<10;i++)
{
a[i]=A%10;
A=A/10;
}
for(i=0;i<10;i++)
{
mid_result+=a[i];
}
/* if(mid_result>=10)
{
result=resolve(mid_result);
}*/
if(mid_result<10)
result=mid_result;
else
result=resolve(mid_result);
return result;
}
main()
{
int result[10]={0};
int i=0,A;
printf("Input\n");
scanf("%d",&A);
while(A!=0)
{
result[i]=resolve(A);
scanf("%d",&A);
i++;
}
printf("Output\n");
for(i=0;i<10;i++)
{
if(result[i]==0)
break;
else
printf("%d\n",result[i]);
}
}