#include<bits/stdc++.h>
using namespace std;
#define D(x) cerr<<__LINE__<<" : "<<#x<<" -> "<<x<<endl

const int MAX = 1e2+7;
long long a, b, h1, h2, H, jump, req, total;
string s;

int main() {
    cin>>s;
    total = s[0] - '0';
    while(s.length()>1) {
        total = 0;
        for(int i = 0; i<s.length(); i++) {
            total += s[i]-'0';
        }
        s = to_string(total);
    }
    cout<<total<<"\n";
}
