#include <bits/stdc++.h>
using namespace std;
int h(int n){
int b=0;
while(n!=0){
b=b+n%10;
n=n/10;
}
return b;
}
int main(){
int n;
cin>>n;
int b=h(n);
while(b>=10){
b=h(b);
}
cout<<b<<endl;
}
/**************************************************************
Problem: 1514
User: chenlingxuan
Language: C++
Result: Accepted
Time:12 ms
Memory:2072 kb
****************************************************************/