#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int64_t N; cin >> N; auto f = [](int64_t x) { int64_t res = 0; while (x > 0) { res += x % 10; x /= 10; } return res; }; for (int i = 0; i < 99; i++) { N = f(N); } cout << N << '\n'; return 0; }