#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void process(int& a){
	int nx = 0, a_copy = a;
	while (a_copy){
		nx += a_copy % 10;
		a_copy /= 10;
	}
	a = nx;
}

int main(void){
	int N; cin >> N;
	int t = 99;
	while (t--) process(N);
	cout << N << endl;
	return 0;
}