#include #define fi first #define se second #define vi vector #define vpi vector> #define vll vector #define vpll vector> #define endl '\n' #define si(v) int(v.size()) #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep2(i, n, m) for (ll i = n; i <= (m); ++i) #define rep3(i, n, m) for (ll i = n; i >= (m); --i) template void chmax(T &a, U b) { if (a < b) a = b; } template void chmin(T &a, U b) { if (b < a) a = b; } using ll = long long; using ld = long double; using namespace std; constexpr ll MOD = 1000000007; signed main() { cout << fixed << setprecision(20); ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; auto f = [&](int x) { int res = 0; while (x) { res += x % 10; x /= 10; } return res; }; while (true) { int keta = si(to_string(n)); if (keta == 1) { cout << n << endl; return (0); } n = f(n); } return (0); }