#include<iostream>
using namespace std;
long long digit(long long a)
{
    long long Sum=0;
    while(a!=0)
    {
        Sum=Sum+a%10;
        a=a/10;
    }
    return Sum;
}
int main()
{
    long long a;
    cin>>a;
    while(1)
    {
        if(a>=0 && a<=9)
        {
            cout<<a<<endl;
            break;
        }
        else
        a=digit(a);
    }
}
