#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3F3F3F3F;
const int maxn = 2e5 + 555;
const int MOD = 1e9 + 7;
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout << fixed;
    string a;
    cin >> a;
    while (a.size() > 1) {
        int ans = 0;
        for (int i = 0; i < (int)a.size(); i++) {
            ans += a[i] - '0';
        }
        a=to_string(ans);
    }
    cout << a << endl;
    return 0;
}