//header{{{ #pragma GCC optimize("Ofast") #include #include #include #include //#include //#include //#include using namespace std; //using namespace boost::multiprecision; //using namespace boost::math; /* typedef boost::adjacency_list > Graph; */ #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() #define Fixed fixed << setprecision(12) #define bsort boost::sort::spreadsort::spreadsort #define int int_fast64_t using pii = pair; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9+7; constexpr int mod2 = 998244353; template class FixPoint : Func { public: explicit constexpr FixPoint(Func&& f) noexcept : Func(forward(f)) {} template constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(*this, std::forward(args)...); } }; template static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint{forward(f)}; } template inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } template using min_heap = priority_queue,greater >; template using max_heap = priority_queue; template using umap = unordered_map; inline int square(int a){ return a * a;} inline int updiv(int a,int b){ return (a + b - 1) / b; } constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; struct negrightshift { inline int operator() (const int &x, const unsigned offset) { return -(x >> offset); } }; //}}} int dsum(int n){ int sum = 0; while(n){ sum += n % 10; n /= 10; } return (sum); } signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout.setf(ios_base::fixed); cout.precision(10); int n; cin >> n; while(true){ int x = dsum(n); if(x == n) return cout << x << '\n', 0; n = x; } return 0; }