#include<bits/stdc++.h>
using namespace std;
int h(int x){
	int s=0;
	while(x){
		s+=x%10;
		x/=10;	
	}
	return s;
}
void ss(int x){
	if(x<10){
		cout<<x;
		return;
	}
	ss(h(x));
}
int main(){
	int n;
	cin>>n;
	ss(n); 
return 0;}

/**************************************************************
	Problem: 1514
	User: fzy001
	Language: C++
	Result: Accepted
	Time:7 ms
	Memory:2072 kb
****************************************************************/