#include<iostream>
using namespace std;
int main()
{
int n;
while(cin >> n)
{
int x = n;
while(x / 10 != 0)
{
int t = x, sum = 0;
while(t != 0) {
sum += t % 10;
t /= 10;
}
x = sum;
}
cout << x << endl;
}
return 0;
}