#include using namespace std; int main(){ int N; cin >> N; N %= 9; cout << (N ? N : 9) << endl; return 0; }