#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second constexpr char ln = '\n'; const int mx=100010; const ll mod=1e9+7; int main(){ ll n; cin >> n; rep(i,99){ ll tmp = 0; while(n>0){ tmp += n%10; n /= 10; } n = tmp; } cout << n << ln; return 0; }