#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll sum(ll n)
{
    ll sum = 0;
    while (n)
    {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    while (n >= 10)
    {
        n = sum(n);
    }
    cout << n << endl;
}