#include<bits/stdc++.h>
using namespace std;

int n; 

int main(){
	cin>>n;
	
	int sum=0,temp=0;
	while(n>=9){
		sum=0;
		temp=n;
		while(temp!=0){
			sum=sum+temp%10;
			temp=temp/10;
		}
		if(sum%9==0){//各数位的和模9的余数 等于 该数模9的余数  
			n=9;
			break;
		} 
		n=sum;
	}
	cout<<n<<endl;
    return 0;
}