#include <iostream>
using namespace std;
long long sol(long long N) {
while (N >= 10) {
long long res = 0;
while (N > 0) {
res += N % 10;
N /= 10;
}
N = res;
}
return N;
}
int main() {
long long N;
cin >> N;
cout << sol(N);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKbG9uZyBsb25nIHNvbChsb25nIGxvbmcgTikgewogICAgd2hpbGUgKE4gPj0gMTApIHsKICAgICAgICBsb25nIGxvbmcgcmVzID0gMDsKICAgICAgICB3aGlsZSAoTiA+IDApIHsKICAgICAgICAgICAgcmVzICs9IE4gJSAxMDsKICAgICAgICAgICAgTiAvPSAxMDsKICAgICAgICB9CiAgICAgICAgTiA9IHJlczsKICAgIH0KICAgIHJldHVybiBOOwp9CgppbnQgbWFpbigpIHsKICAgIGxvbmcgbG9uZyBOOwogICAgY2luID4+IE47CiAgICBjb3V0IDw8IHNvbChOKTsKICAgIHJldHVybiAwOwp9Cg==