#include "bits/stdc++.h" using namespace std; // コンテスト中のみ #define int long long #define ll long long #define rep(i,n) for(int i = 0; i < (n); i++) #define P pair int MOD = 1000000007; const ll INF = 1LL << 60; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vectora(100); a[0] = n; rep(i, 100) { if (i == 0)continue; string tmp = to_string(a[i - 1]); int now = 0; rep(j, tmp.size())now += tmp[j] - '0'; a[i] = now; } cout << a[99] << endl; return 0; }