#include <bits/stdc++.h>
using namespace std;
int num = 10, ans = 0;
string s;
int main(){
cin >> s;
while (num > 9){
for (int i = 0; i < s.size(); i++){
ans += s[i] - '0';
}
s = to_string(ans);
num = ans;
ans = 0;
}
cout << num;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBudW0gPSAxMCwgYW5zID0gMDsKc3RyaW5nIHM7CmludCBtYWluKCl7CgljaW4gPj4gczsKCXdoaWxlIChudW0gPiA5KXsKCQlmb3IgKGludCBpID0gMDsgaSA8IHMuc2l6ZSgpOyBpKyspewoJCQlhbnMgKz0gc1tpXSAtICcwJzsKCQl9CgkJcyA9IHRvX3N0cmluZyhhbnMpOwoJCW51bSA9IGFuczsKCQlhbnMgPSAwOwoJfQoJY291dCA8PCBudW07Cn0=