#include #define inf (int)1e18 #define EPS 1e-9 #define MOD 1000000007 #define Pi 3.14159 #define rep(i,a,n) for (int i=a;i #define vi vector #define ml map #define umap unordered_map using namespace std; void sol() { ll n; cin >> n; ll a[1005]; ll cnt, k = 0; while (n > 10) { cnt = 0; while (n != 0) { a[cnt] = n % 10; n /= 10; cnt++; } for (ll i = cnt - 1; i >= 0; --i) k += a[i]; n = k; k = 0; } cout << n << '\n'; } int main() { int t = 1; // cin >> t; while (t--) { sol(); } return 0; }