#include <iostream>
using namespace std;
int n;
int h(int a){
int b=0;
while(a!=0){
b=b+a%10;
a/=10;
}
return b;
}
void f(int x){
if(x<10){
cout<<x;
}else{
f(h(x));
}
}
int main(){
cin>>n;
f(n);
}
/**************************************************************
Problem: 1514
User: linzihang
Language: C++
Result: Accepted
Time:14 ms
Memory:2072 kb
****************************************************************/