#include using namespace std; using ll = long long; constexpr char newl = '\n'; int calc(int n) { int res = 0; while (n > 0) { res += n % 10; n /= 10; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; for (int i = 1; i < 100; i++) { n = calc(n); } cout << n << newl; return 0; }