#include <iostream>
#include <math.h>
using namespace std;
int a;
int main()
{
    cin >> a;
    int prev = a;
    while (true) {
        int tmp = 0;
        while (prev) {
            tmp += prev % 10;
            prev /= 10;
        }
        if (tmp < 10) {
            cout << tmp << endl;
            break;
        } else {
            prev = tmp;
        }
    }
}
