#include <bits/stdc++.h>
using namespace std;
string n;
long long tcs(long long n)
{
    long long res = 0;
    while(n)
    {
        res+=n%10;
        n/=10;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    freopen("timso.inp","r",stdin);
    freopen("timso.out","w",stdout);
    cin >> n;
    long long res = 0;
    for(int i = 0; i < n.size(); i++)
    {
        res+=(int)n[i]-48;
    }
    while(res>9)
    {
        res = tcs(res);
    }
    cout << res;
    return 0;
}
