#include <iostream>
using namespace std;
int root(int a)
{
    int s = 0;
    while(a > 0)
    {
        s += a % 10;
        a /= 10;
    }
    if(s > 9) return root(s);
    else return s;
}
int main()
{
    int a;
     cin >> a;
    cout << root(a) << endl;
   return 0;
}