#include<iostream>
using namespace std;

int getSum(int n)
{
	int res = 0;
	while(n)
	{
		res = res + (n % 10);
		n /= 10;
	}
	return res;
}

int main(void)
{
	int n;
	while(cin >> n)
	{
		while(n >= 10) n = getSum(n);
		cout << n << endl;
	}
	return 0;
}