#include <bits/stdc++.h>

using namespace std;

int main() {
    long a, root=0;
    cin >> a;
    while(a!=0) {
        root += a%10;
        a /= 10;
    }
    root %= 9;
    if(root==0)
        root = 9;
    cout << root << endl;
    return 0;
}