#include<cstdio>
#include<cmath>
using namespace std;
int cw(int);
int main(){
int f;
scanf("%d",&f);
cw(f);
while(f>=10){
cw(f);
}
printf("%d",f);
return 0;
}
int cw(int n){
int a[1000];
int d,b=0,zh=0;
for (int i=1;n>=10;++i){
d=n%10;
a[i]=d;
++b;
n=(n-d)/10;
}
++b;
a[b]=n;
for (int e=1;e<=b;++e){
zh+=a[e];
}
n=zh;
return n;
}