#include<bits/stdc++.h>
using namespace std;
int he(int x){
int sum=0;
while(x>0){
//789%10=9
sum+=x%10;
x=x/10;
}
return sum;
}
void f(int x){
if(x<10) {
cout<<x;
return;
}
else{
f(he(x));
}
//压缩
}
int main(){
int n;
cin>>n;
f(n);
return 0;
}
/**************************************************************
Problem: 1514
User: admin
Language: C++
Result: Accepted
Time:8 ms
Memory:2072 kb
****************************************************************/