#include using namespace std; int main() { int N; cin >> N; if(N%9==0){ cout << 9; } else{ cout << N%9; } }